headLink and headScript are causing layout error

For programming and general questions on Zend Framework
Post Reply
abedn84
Posts: 5
Joined: Thu Jul 07, 2011 12:53 pm

headLink and headScript are causing layout error

Post by abedn84 » Wed Jun 05, 2013 12:37 pm

Hi everyone,

I have been struggling all day now with a weird issue here.
At some point, whenever I am echoing the $this->headLink or $this->headScript on a single view, I am getting the error:

Uncaught exception 'Zend_View_Exception' with message 'script 'layout.phtml' not found in path


Here is my bootstrap view instance:

protected function _initView()
{

//register the jQuery functionality inside the view object
$view = new Zend_View();
$BASE_URl = Zend_Registry::get('BASE_URL');

//Add global title
$view->headTitle( 'Nymgo' );
$view->doctype('XHTML1_STRICT');
$langSession = new Zend_Session_Namespace('language');
$styleLang = $langSession->lang;

//Add global css links
$view->headLink()->setStylesheet('http://zend-me.com/application/views/css/'. $styleLang .'/style.css');
$view->headScript()->appendFile('http://zend-nymgo.com/application/scripts/common.js', 'text/javascript');

//add it to the view renderer
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
$viewRenderer->setView($view);

return $view;

}

Then on the index of the controller:

public function viewAction()
{

$this->_helper->layout->disableLayout();
}


Finally on the view script:

<?php echo $this->doctype(); ?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<?php echo $this->headTitle(); ?>
<?php //echo $this->headScript() ?>
<?php echo $this->jQuery(); ?>

<?php $this->headLink()->prependStylesheet('/application/views/css/EN/style.css') ?>
<?php echo $this->headLink(); ?>

</head>

etc...


If I uncomment the echos of headScript and headLink , the error disappears.

I also have a style.css script on application/something/css/style.css but when set in the headLink, it seems not to be reading the file although the href is the correct one.


Any help would be much appreciated.

thanks

amar9111
Posts: 18
Joined: Tue Apr 30, 2013 9:48 am

Re: headLink and headScript are causing layout error

Post by amar9111 » Thu Jun 13, 2013 11:59 pm

$view->headLink()->setStylesheet('http://zend-me.com/application/views/css/'. $styleLang .'/style.css');
$view->headScript()->appendFile('http://zend-nymgo.com/application/scripts/common.js', 'text/javascript');

you should add these lines in your view script and try

$view->headLink()->setStylesheet($this->baseUrl().'/'. $styleLang .'/style.css');
$view->headScript()->appendFile($this->baseUrl().'/scripts/common.js');
or
<?php echo $this->headLink()->appendStylesheet('/../css/style.css') ?>

Post Reply