Jump to content
Sign in to follow this  
rat_clot

Mudar layout no Zend Framework

Recommended Posts

rat_clot

Boas, sou iniciante em Zend Framework, e estou com um erro que não consigo resolver nem encontrar solução na net.

Quero alterar o layout do site quando alguém está logado.

Este é o meu ficheiro bootstrap:

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initAuthState()
    {
if (Zend_Auth::getInstance()->hasIdentity()):
// Logged in.
$layout->setLayout(‘layout2’);

else:
// Not Logged in.
$layout->setLayout(‘layout’);
endif;
    }

}

Este é o erro que me dá:

Fatal error: Call to a member function setLayout() on a non-object in /home/zerego/application/Bootstrap.php on line 13

Se alguém souber qual é o problema agradecia.

Fiquem bem

Share this post


Link to post
Share on other sites
rat_clot

Obrigado Yoda, desculpa lá mas eu sou mesmo iniciante nisto, e também só tive aulas de php durante uns 6 meses ou pouco mais. 

agora estou com outro erro, que supostamente o layout2.phtml não existe na pasta:

Fatal error: Uncaught exception 'Zend_View_Exception' with message 'script '‘layout2’.phtml' not found in path (/layouts/scripts/:./views/scripts/)' in /home/zerego/library/Zend/View/Abstract.php:976 Stack trace: #0 /home/zerego/library/Zend/View/Abstract.php(876): Zend_View_Abstract->_script('?layout2?.phtml') #1 /home/zerego/library/Zend/Layout.php(796): Zend_View_Abstract->render('?layout2?.phtml') #2 /home/zerego/application/Bootstrap.php(13): Zend_Layout->render() #3 /home/zerego/library/Zend/Application/Bootstrap/BootstrapAbstract.php(662): Bootstrap->_initAuthState() #4 /home/zerego/library/Zend/Application/Bootstrap/BootstrapAbstract.php(615): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('authstate') #5 /home/zerego/library/Zend/Application/Bootstrap/BootstrapAbstract.php(579): Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap(NULL) #6 /home/zerego/library/Zend/Application.php(355): Zend_Application_Bootstrap_BootstrapAbstract->bootstrap(NULL) #7 /home/zerego/public_html/index.php(25): Zen in /home/zerego/library/Zend/View/Abstract.php on line 976

Eu tenho criado o layout2.phtml e está na mesma pasta que o layout.phtml. O caminho que tenho definido no "aplications.ini" é este:

resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"

O bootstrap está assim:

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initAuthState()
    {
$layout = new Zend_Layout;
$layout->setLayoutPath('/layouts/scripts');

if (Zend_Auth::getInstance()->hasIdentity()):
// Logged in.
$layout->setLayout(‘layout2’);
$layout->render();

else:
// Not Logged in.
$layout->setLayout(‘layout’);
endif;
    }

}

Se me conseguirem ajudar outra vez, agradecia.  ;)

Fiquem bem

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.