Zend navigation object empty in view phtml - zend-framework

I have a module based application with a default and a user module.
My Navigation menu which is called from the layout is working fine, but now want to create a sidemenu. I would like to call it from the e.g. language.phtml in user/settings/language.
in my language.phtml
...
<?php echo $this->navigation()->menu()
->setPartial('partials/sidemenu.phtml')
->render(); ?>
...
This partial is in the scripts directory in the user module.
The partial is being called but for some reason the navigation/container object is empty.
Thanks in advance!
Peter

Related

Zend view , Plugin not found

i am creating email templates using the zend view class, and assigning variables..
i am also using helpers withing the view script file, but it has the errors when rendered:
Message: Plugin by name 'EmTpl' was not found in the registry; used paths: Zend_View_Helper_: Zend/View/Helper/:/application/modules/customers/views/helpers/
however, this plugin exists when i use the on dispatch, as in loading a controller with a view script that loads this helper called 'EmTpl'.
this is my script for emails:
$html = new \Zend_View();
$html->setScriptPath(APPLICATION_PATH . '/modules/admin/views/scripts/emails/');
//$html->addHelperPath('Zend/View/Helper/','Zend_View_Helper_');
$html->addHelperPath(
APPLICATION_PATH . '/modules/customers/views/helpers/','Zend_View_Helper_'
);
$html->render("customer-new.phtml");
and inside my customer-new.phtml,
theres:
<body>
hello, <?=$this->name?>
<?=$this->emTpl?>
</body>
this plugin works fine when called in controller view scripts...
but i want it to work with my email templates script.
thanks
you have to add helper paths before you set the script path...

how to append script file in zend framework

My layouts are placed inside layout/scripts/layout.phtml
i have placed the below code inside my head section of layout.phtml
<?php
print $this->headScript()->appendFile($this->baseUrl().'/js/jquery-1.7.2.min.js')
->appendFile($this->baseUrl().'/js/simpla.jquery.configuration.js');
?>
Now I want to append another javascript file from a view. For that I wrote the following code:
$this->headScript()->appendFile($this->baseUrl().'js/fancybox/jquery.fancybox-1.3.4.pack.js');
Although this appended the file but it appears before my jquery-1.7.2.min.js. What i want is that i want to add jquery.fancybox-1.3.4.pack.js below my jquery-1.7.2.min.js
How can i do this?
Your view script is rendered before the layout so the calls to appendFile() in your layout result in those scripts (jquery-1.7.2 and simpla.jquery) being appended after the one you appended in the view script.
To fix this, use prependFile() in your layout at least for the main jQuery script.
Your layout might look like this:
<?php
print $this->headScript()
->appendFile($this->baseUrl().'/js/simpla.jquery.configuration.js')
->prependFile($this->baseUrl().'/js/jquery-1.7.2.min.js');
No need to change the view script, that is fine as is.
See HeadScript Helper Example #23 which talks a bit about ordering of the scripts.
The important thing to remember that they don't mention is that your view script gets rendered before the layout does.

Zend-Framework View Helper - Is it specific view related?

When we create a view helper, on a Zend application, will that helper be available for ALL the views or, should we somehow tell that THAT view helper is available to a specific view?
What if, on the view folder "something", we have more then one file ? Any of those files can call it?
Thanks a lot,
MEM
When you call a view helper, the framework will look within the paths defined via $view->addHelperPath(). Typically, such a call will include a pseudo-namespace as well as a path:
$view->addHelperPath('My/View/Helper', 'My_View_Helper_');
Then when you call a view helper in a layout or a view script:
<?php echo $this->someHelper() ?>
The framework will do a LIFO search, appending the prefixes (in the above case: 'My_View_Helper_') to the classname 'SomeHelper' and then attempting to load the file defined by the addHelperPath() mapping.
In the default setup, the framework pre-loads the Zend view helpers by calling:
$view->addHelperPath('Zend/View/Helper', 'Zend_View_Helper_');
which is why you can use all the Zend-provided view helpers right out of the box.
Since all this processing is independent of which view script is making the call, it will work in any view script. [There are actually some issues associated to calling view helpers defined in other modules, but that's a separate issue.]

How to access controller name and action name form layout file in zend framework

I know to how to get controller name and action name from layout.phtml file so that i can make dynamic css.
Try this:
Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
Zend_Controller_Front::getInstance()->getRequest()->getActionName();
You shouldn't really have logic in your layout.
Best inject your css from your controller using the headlink container.
So in your controller...
$this->view->headLink()->appendStylesheet('custom_stylesheet.css');
And in your layout...
echo $this->headLink();
Simple as that! :)
for finding controller name and action name in zend use this in controller
Zend_Controller_Front::getInstance()->getRequest()->getControllerName()
Zend_Controller_Front::getInstance()->getRequest()->getActionName()
<?php
echo $this->headLink()->appendStylesheet($this >baseUrl().'path to your css file without public folder');
?>

dojo.require required in Zend Framework's view helpers?

I've tried using a Dojo button view helper, but it appears that Zend will not automatically generate a dojo.require('dijit.form.Button'). Is this correct behavior?
Here's excerpt from my layout script:
<head>
<?= $this->dojo()->setDjConfigOption('usePlainJson',true)->addStylesheetModule('dijit.themes.claro')->setLocalPath("/js/dojo/dojo.js"); ?>
</head>
...
<?= $this->button('test', 'test') ?>
And this is in my bootstrap:
public function _initDojo() {
$view = $this->getResource('view');
$view->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper');
Zend_Dojo::enableView($view);
Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
}
All other Dojo-specific code is rendered properly, except the dojo.require.
I've not used the dijit helpers on their own so I only have a partial answer for you.
ZF definitely automatically adds the appropriate requires when you use dijit elements in Zend_Dojo_Form. From looking at the helper code it looks like this should happen when you use them on their own as well.
If you are really calling $this->button in your layout as in your example, then I would guess that it's not working simply because the dojo helper has already run by the time your helper is called. You could try moving the same call to a view script instead to see if this solves the problem (view scripts are rendered before layouts).