Issues

ZF-7357: dojo is not work when i use it in one action not the defualt indexAction() , the error: the dojo.js is nto defined!

Description

first step, I make a dir named "js" in the public directory, I copy the dojo library in the dir "js" second step, in the Bootstrap.php protected function _initDoctype() { $this->bootstrap('view'); $view = $this->getResource('view'); $view->doctype('XHTML1_TRANSITIONAL'); $view->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper'); }

3th step, in the layout.phtml

<?php if ($this->dojo()->isEnabled()){ $this->dojo()->setLocalPath('js/dojo/dojo.js') ->addStyleSheetModule('dijit.themes.tundra'); echo $this->dojo(); } ?>

forth step, A controler named UserControler.php , there is a loginAction() ,in the login.phtml view file,

<?php $this->dojo()->enable() ->setDjConfigOption('parseOnLoad', true) ->setDjConfigOption('isDebug', true) ->requireModule('dojo.io.script'); ?> if i request , http://127.0.0.1/user/login , the problem will come , " dojo.js is not defined!"

why?

Comments

The first problem is where you call setLocalPath(). Prefix it with either a '/' or with the base URL to your application (which should also include a '/' at the beginning):


$this->dojo()->setLocalPath('/js/dojo/dojo.js');

// or
$baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
$this->dojo()->setLocalPath($baseUrl . '/js/dojo/dojo.js');

If you don't have the leading slash, then it will look for js/dojo/dojo.js relative to the current url -- so, in your example, '/user/login/js/dojo/dojo.js', instead of '/js/dojo/dojo.js' which is what you really want.

The second problem: Don't check for "if ($this->dojo()->isEnabled())" in your view script. Do your Dojo setup in your bootstrap, and selectively enable it within your various view scripts. In your layout, just call '<?php echo $this->dojo() ?>' -- which will render it if enabled, and do nothing if not enabled.