I want to include external js file in my php script. I am following zend framework.Right now I am adding js file in controller's init function like this.
public function init() {
$this->doUserAuthorisation();
parent::init();
$this->view->headScript()->appendFile($this->view->baseUrl().'/js/front_cal/jquery-1.3.2.min.js');
$this->view->headLink()->setStylesheet($this->view->baseUrl().'/styles/front_cal/calendar.css');
}
problem what i am facing is, js file doesnot include.Is this the right way to include js file?
JavaScript (and images, CSS, flash movies, etc) belong to the view layer so configure them there.
For globally included files, add them to your layout, eg
Your view scripts can then add assets to the helpers which are echoed out in the layout. As the layout uses the
prepend*()
methods, the global files will be displayed first, egIn above solution the 'path/to/file.js' script will be included in the header twice. There is no need for
echo
before callingprependFile
. Such behaviour can lead to duplicating javascript controls.<!-- layout.phtml --> <head> <?php echo $this->headScript()->prependFile( $this->baseUrl('path/to/file.js')) // this will echo out the whole prependFile queue