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:
- creates the needed code
- puts the JQuery script in the head tag
But when used inside the layout
- 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
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.
Edit:
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>
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>
I experience the same problem WITH AJAXLINK.
The link is generated using this helper in a LAYOUT, but the JQUERY function which should do the AJAX call in the header NOT.
It works all perfect if I try the same in a VIEW.
Edit: I ended up in copying the ajax-code manually into the layout without using the ajaxlink-helper.
And I opened up a bug report here: http://framework.zend.com/issues/browse/ZF-10317