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...
Related
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
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.]
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).
How can i add my own jQuery plug-in located in my zf path "public/js/isround.js"?
- to apply using Zend framework instead of manually putting this:
<script> $("#world").isRound('myPlugin'); </script>
jQuery setup is working
$this->jQuery()->setLocalPath('http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js')
->enable()
->setUiLocalPath('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js')
->uiEnable()
->addStylesheet('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/ui-lightness/jquery-ui.css');
file application/views/scripts/index/index.phtml, i have:
< div id="world"> _____my js plugin apply here _____< /div>
is this what you are looking for?
$this->headScript()->appendFile('/js/isround.js');
Use a view helper.
zend documentation
Check out:
Example #2 Building your own Helper with No Conflict Mode
Also a tutorial about viewhelpers and jquery Zendcast
Here is some code:
Create a folder in your library folder called Mylib.
In it create a folder views.
In views create a folder helpers.
In helpers create a file named: IsRound.php
<?php
class Mylib_Views_Helpers_IsRound {
public function isRound($elem){
echo '<script type="text/javascript">$("'.$elem.'").isRound();</script>';
}
}
In the indexAction in IndexController.php
$this->view->addHelperPath('Mylib/views/helpers', 'Mylib_Views_Helpers');
In index.phtml:
<?php $this->isRound('#elem'); ?>
Hope this helps!
I am very to new to zend frame work , I am trying to set up a project (Done by other programmer) in my local server, i have setted up this project, but all pages are styless in my browser, ie the CSS files are not taken in phtml pages, For solving this issue which file I have ti Edit?
Plss Help me
It depends upon the directory structure that your app has adapted. However checkout if you have views/scripts directory then, again depending upon the directory style used, the header.phtml file (if exist) will have invalid link to css.
If you dont have header.phtml, then use any text-editor and search in your views directory with keyword 'css', and you will get to know the possible file name.
Global css files I would add in the bootstrap file and any styles that relate to a page I would add in the relevant controller action for example...
global styles in bootstrap file
protected function _initView()
{
$this->view = new Zend_View();
$this->view->headLink()->appendStylesheet('css/global.css');
}
or in a specific controller action
public function myPageAction()
{
$view = $this->view;
$view->headLink()->appendStylesheet('css/myPageStyles.css');
}