如何在布局中启用ZendX集成的Jquery [英] How to enable ZendX integrated Jquery in Layouts

查看:101
本文介绍了如何在布局中启用ZendX集成的Jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解为什么直接在布局中使用ZendX_JQuery时不起作用.在视图中时效果很好:

I am trying to understand why ZendX_JQuery will not work when used directly in a layout. It works perfectly fine when in a view:

  • 创建所需的代码
  • 将JQuery脚本放入 head 标记

但是当在布局内使用时

  • 创建所需的代码
  • 将JQuery脚本插入 head 标记
  • creates the needed code
  • does not insert the JQuery script in the head tag

这可以克服吗?如何解决?而且,如果有人可以回答这个问题,为什么要这样做呢?

Can this be overcome, and how? And, if anyone can answer this, why is it doing this?

为了清楚起见,这是我想做的事情:

To make it perfectly clear, here is what i want to do:

    //layout.phtml file
    <head>
    <?php echo $this->jQuery();?>
    </head>
    <body>
<?php echo $this->ajaxLink("Like",

                    "/mod/instr/like/id/".$this->books['id'],

                    array('update' => '#ajaxed',
                    'beforeSend'=>'fadeout'
                    ));
?>
<?php echo $this->layout()->content; ?>
    </body

这意味着,我希望将jQuery对象放入布局中.我想在布局文件中放置一些与jQuery相关的代码 Directly ,而不仅仅是将jQuery初始化为需要它的视图的部分.

It means, that I wish to put a jQuery object inside a layout. I want to put some jQuery related code DIRECTLY inside my layout file, not just the part that allows jQuery to initialized for the views that require it.

好的,这是Bootstrap中的init函数

Ok, so here's the init function in the Bootstrap

    protected function _initJqueryLoad()
    {

        $view = new Zend_View();
     // $view->addHelperPath('ZendX/JQuery/View/Helper/', 'ZendX_JQuery_View_Helper');
$view->addHelperPath("ZendX/JQuery/View/Helper", "ZendX_JQuery_View_Helper");
    $view->jQuery()->addStylesheet('/js/jquery/css/ui-lightness/jquery-ui-1.7.2.custom.css')
        ->setLocalPath('/js/jquery/jquery.js')
        ->setUiLocalPath('/js/jquery/js/jquery-ui-1.7.2.custom.min.js');
ZendX_JQuery::enableView($view);
    }

我的布局文件的头部包含以下内容:

My layout file contains this in the head:

    <?php echo $this->headLink()->prependStylesheet($this->baseUrl().'/css/admin.css'); ?>
    <?php echo $this->headLink()->prependStylesheet($this->baseUrl().'/css/form.css'); ?>
<?php 
echo $this->headScript()->prependFile('/js/JP.js','text/javascript','');?>
<?php echo  $this->jQuery(); ?>
</head>

因此,应在每个使用此布局的视图中启用JQuery. 在我的视图中但不在我的布局中运行的代码是:

So the JQuery should be enabled in every view that uses this layout. The code that runs in my views, but not in my layouts is:

<div id="ajaxed">
<? 
echo $this->ajaxLink("Like",

                    "/mod/instr/like/id/".$this->books['id'],

                    array('update' => '#ajaxed',
                    'beforeSend'=>'fadeout'
                    ));
                     echo $this->ajaxLink("Don't like",

                    "/mod/instr/hate/id/".$this->books['id'],

                    array('update' => '#ajaxed'));?>


</div>

推荐答案

我在使用AJAXLINK时遇到同样的问题.

I experience the same problem WITH AJAXLINK.

使用此帮助程序在LAYOUT中生成链接,但是应该在标题NOT中执行AJAX调用的JQUERY函数.

The link is generated using this helper in a LAYOUT, but the JQUERY function which should do the AJAX call in the header NOT.

如果我在VIEW中尝试同样的方法,那么一切都完美.

It works all perfect if I try the same in a VIEW.

我最终不使用ajaxlink-helper将ajax代码手动复制到布局中.

I ended up in copying the ajax-code manually into the layout without using the ajaxlink-helper.

我在这里打开了一个错误报告: http://framework.zend. com/issues/browse/ZF-10317

And I opened up a bug report here: http://framework.zend.com/issues/browse/ZF-10317

这篇关于如何在布局中启用ZendX集成的Jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆