add script paths to view in modules' bootstrap (Zend_Applica

For programming and general questions on Zend Framework

add script paths to view in modules' bootstrap (Zend_Applica

Postby nick-knight on Mon Jun 08, 2009 5:05 pm

Hello,

Where is the problem in addition view script paths in module bootstrapers?
For example:
In one module name "Module" I create new layout instance and get view of it.
Then I add view scripts paths.

Code: Select all
class Module_Bootstrap extends Zend_Application_Module_Bootstrap
{
    protected function _initModule()
    {       
        ....
        $view = $layout->getView();

        //Add paths
        foreach ($paths as $path) {
            $view->addScriptPath($app);
        }

        return $view;
    }
}



But no effect!
Code: Select all
class Module_Bootstrap extends Zend_Application_Module_Bootstrap
{
    protected function _initModule()
    {       
        ....
        $view = $layout->getView();

        //Add paths
        foreach ($paths as $path) {
            $view->addScriptPath($app);
        }

        $paths = $view->getScriptPaths();
        foreach ($paths as $p) {
            echo $p . "<br />";
        }
        exit;


        return $view;
    }
}
nick-knight
 
Posts: 6
Joined: Mon Jun 08, 2009 4:57 pm

Re: add script paths to view in modules' bootstrap (Zend_Applica

Postby brunitto on Mon Jun 08, 2009 5:40 pm

Where are the $paths variable?
Ookie dookie!
brunitto
 
Posts: 111
Joined: Fri May 29, 2009 10:10 pm
Location: São Paulo - Brazil

Re: add script paths to view in modules' bootstrap (Zend_Applica

Postby nick-knight on Mon Jun 08, 2009 9:11 pm

$paths variable exists.
for example it is:

Code: Select all
$paths = array();
$app_bootstrap = $this->getApplication();   
$app_layout = $app_bootstrap->getResource('layout');
$app_layout_path = $app_layout->getLayoutPath();

array_push($paths, $app_layout_path);
nick-knight
 
Posts: 6
Joined: Mon Jun 08, 2009 4:57 pm

Re: add script paths to view in modules' bootstrap (Zend_Applica

Postby brunitto on Mon Jun 08, 2009 10:17 pm

You forgot to inject the view object within the ViewRenderer helper...

Code: Select all
...
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
$viewRenderer->setView($view);

// Returns the view resource to bootstrap resources registry
return $view;


So when your controllers try to render some view script through ViewRenderer, it will use a 'clean' Zend_View object.
Ookie dookie!
brunitto
 
Posts: 111
Joined: Fri May 29, 2009 10:10 pm
Location: São Paulo - Brazil

Re: add script paths to view in modules' bootstrap (Zend_Applica

Postby nick-knight on Tue Jun 09, 2009 8:43 am

brunitto wrote:You forgot to inject the view object within the ViewRenderer helper...


yes, I've add to it to ViewRenderer helper but, after path insertion:

(for windows)
Fatal error: Uncaught exception 'Zend_View_Exception' with message 'script 'head.tpl' not found in path (G:\WebServer\www\beta\application\modules\users\layouts\scripts\;G:\WebServer\www\beta\application\modules\default\views\scripts\;G:\WebServer\www\beta\application\modules\users\layouts\scripts\;G:\WebServer\www\beta\application\modules\users\views\scripts\;Array\;.\views\scripts\)'

added path is as Array\;
but it is a string = G:\WebServer\www\beta\application\layouts\scripts\;
nick-knight
 
Posts: 6
Joined: Mon Jun 08, 2009 4:57 pm

Re: add script paths to view in modules' bootstrap (Zend_Applica

Postby brunitto on Tue Jun 09, 2009 2:23 pm

How did you defined your layout resourcein application.ini?

Or had you used a initialization method as well?
Ookie dookie!
brunitto
 
Posts: 111
Joined: Fri May 29, 2009 10:10 pm
Location: São Paulo - Brazil

Re: add script paths to view in modules' bootstrap (Zend_Applica

Postby nick-knight on Tue Jun 09, 2009 4:03 pm

brunitto wrote:How did you defined your layout resourcein application.ini?
Or had you used a initialization method as well?


In ini file:

Code: Select all
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/ini.php'
);

$application->bootstrap()
            ->run();


ini.php
Code: Select all
return array (
   'resources' => array(
                ...      
      'layout' => array(
         'layout' => 'index',
         'layoutPath' => APPLICATION_PATH . '/layouts/scripts',                  
      )
        )
...
);
nick-knight
 
Posts: 6
Joined: Mon Jun 08, 2009 4:57 pm

Re: add script paths to view in modules' bootstrap (Zend_Applica

Postby brunitto on Tue Jun 09, 2009 4:18 pm

As the error indicates, Zend is trying to render a 'head.tpl' file. Are you using third part templates?

Your ini.php is fine - you can sanitize by adding:

Code: Select all
return array (
   'resources' => array(
                ...     
      'layout' => array(
         'layout' => 'index',
         'layoutPath' => APPLICATION_PATH . '/layouts/scripts',
         'viewSuffix' => 'phtml'               
      )
        )
...
);


As you may know, you must have a file named 'index.phtml' within your APPLICATION_PATH/layouts/scripts directory.
Ookie dookie!
brunitto
 
Posts: 111
Joined: Fri May 29, 2009 10:10 pm
Location: São Paulo - Brazil

Re: add script paths to view in modules' bootstrap (Zend_Applica

Postby nick-knight on Tue Jun 09, 2009 6:15 pm

brunitto wrote:As the error indicates, Zend is trying to render a 'head.tpl' file. Are you using third part templates?

Your ini.php is fine - you can sanitize by adding:

Code: Select all
return array (
   'resources' => array(
                ...     
      'layout' => array(
         'layout' => 'index',
         'layoutPath' => APPLICATION_PATH . '/layouts/scripts',
         'viewSuffix' => 'phtml'               
      )
        )
...
);


As you may know, you must have a file named 'index.phtml' within your APPLICATION_PATH/layouts/scripts directory.


No I've not used third party template just determine .tpl suffix for view templates scripts.

The problem is after add path to view it is string Array:
Fatal error: Uncaught exception 'Zend_View_Exception' with message 'script 'head.tpl' not found in path (G:\WebServer\www\beta\application\modules\users\layouts\scripts\;G:\WebServer\www\beta\application\modules\default\views\scripts\;G:\WebServer\www\beta\application\modules\users\layouts\scripts\;G:\WebServer\www\beta\application\modules\users\views\scripts\;Array\;.\views\scripts\)'

and therefore the view script head can be find!

in Zend_Application_Module_Bootstrap
Code: Select all
...
        $view = $layout->getView();

        echo "<br /> before addScriptPath <br />";
        $paths = $view->getScriptPaths();
        foreach ($paths as $p) {
            echo $p . "<br/>";

        }

        //Add paths
        foreach ($app['layout']['paths'] as $path) {
            echo 'added script - ' . $path;
            $view->addScriptPath($app);
        }

        echo "<br /> after addScriptPath <br />";
        $paths = $view->getScriptPaths();
        foreach ($paths as $p) {
            echo $p . "<br/>";

        }
        exit;
...


Output:

before addScriptPath
.\views\scripts\
added script - G:\WebServer\www\beta\application/layouts/scripts
after addScriptPath
Array\
.\views\scripts\

And after we can see Array\ - path, not G:\WebServer\www\beta\application/layouts/scripts
nick-knight
 
Posts: 6
Joined: Mon Jun 08, 2009 4:57 pm

Re: add script paths to view in modules' bootstrap (Zend_Applica

Postby brunitto on Tue Jun 09, 2009 7:54 pm

There is an error here:
Code: Select all
    //Add paths
    foreach ($app['layout']['paths'] as $path) {
        echo 'added script - ' . $path;
        $view->addScriptPath($app);
    }


You are adding a undefined $app variable as a path, you should replace with $path - which contains a $path array item value:
Code: Select all
    //Add paths
    foreach ($app['layout']['paths'] as $path) {
        echo 'added script - ' . $path;
        $view->addScriptPath($path);
    }


Improving...
Code: Select all
    //Add paths
    foreach ($app['layout']['paths'] as $key => $value) {
        echo 'added script - ' . $value;
        $view->addScriptPath($value);
    }


In the error
Fatal error: Uncaught exception 'Zend_View_Exception' with message 'script 'head.tpl' not found in path (G:\WebServer\www\beta\application\modules\users\layouts\scripts\;G:\WebServer\www\beta\application\modules\default\views\scripts\;G:\WebServer\www\beta\application\modules\users\layouts\scripts\;G:\WebServer\www\beta\application\modules\users\views\scripts\;Array\;.\views\scripts\)'

we can notice that the layouts scripts is beeing used, but a 'head.tpl' file is not beeing found. Checkout this issues.
Ookie dookie!
brunitto
 
Posts: 111
Joined: Fri May 29, 2009 10:10 pm
Location: São Paulo - Brazil


Return to Zend Framework

Who is online

Users browsing this forum: No registered users and 4 guests