Zend Framework - how to apply my own js plugin? - zend-framework

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!

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...

Zend navigation object empty in view phtml

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

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).

Zendframework CSS Problem

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');
}