zend framework - Enable jQuery using with ZendX_JQuery in a view helper -
i trying activate jquery through view helper called within layout.
the problem jquery called within layout , renders include files, before defined in view helper.
here scripts :
layout.phtml:
<?php echo $this->doctype(); ?> <html> <head> <?php echo $this->headtitle() ?> <?php echo $this->headlink()->appendstylesheet('/css/base.css') ?> <?php echo $this->headmeta() ?> <?php echo $this->headstyle() ?> <?php echo $this->jquery() ?> </head> <body> [...] <div id="droite" class="column grid_4"> <!-- column 2 start --> <?php echo $this->render('partials/droite.phtml'); ?> <!-- column 2 end --> </div> </body> </html>
partials/droite.phtml:
<?=$this->rolelinks(); ?>
my_view_helper_rolelinks:
<?php class my_view_helper_rolelinks extends zend_view_helper_abstract { public function rolelinks() { if (model_user::hasidentity()) { $role = model_user::getrole(); if ($role === 'admin') { return $this->view->partial('partials/droite_admin.phtml'); return; } } else { return ''; } } }
partials/droite_admin.phtml:
<?php $this->jquery() ->uienable() ->addjavascriptfile('/js/jquery.ui.datepicker-fr.js') ->addjavascriptfile('/js/onload.js'); ?> <div id="calendar"></div>
so.
not sure right way it, main idea check if user admin enable jquery , display datepicker (calendar).
thanks in advance help.
you try check if jquery enabled in layout avoid double inclusion.
<head> <?php echo $this->headtitle() ?> <?php echo $this->headlink()->appendstylesheet('/css/base.css') ?> <?php echo $this->headmeta() ?> <?php echo $this->headstyle() ?> <?php if (! $this->jquery()->isenabled()) { echo $this->jquery(); } ?> </head>
Comments
Post a Comment