A much nicer way to do this is to create a seperate controller for logging in
and out and then use the _forward method

In my news module, indexcontroller, add action (have custom rewrite rules
the mapping is: /:module/:action (indexcontroller is default)(

$this->_forward('login', 'index', 'profile', array('destination' =>
'/news/add'));


This redirects to the profile module, indexController, loginAction and I
give it a parameter destination so I know where to go back to after the
login form has been posted.
Just make sure you set the action of the login form to the proper login
handling (/profile/login in my case)

And do a:

$this->_redirect($destination, array('code' => 303));

Once the user is validated and logged in. (the 303 is the HTTP see Other
header which prevents the post action from entering the history and breaking
the refresh button)

This way the user won't really notice he's being redirected to another
controller (the url stays the same)
and gets right back to where he was before logging in without you having to
do complex login stuff in your other controllers :D

This leaves the url intact 


Nogyara wrote:
> 
> Hi all,
> maybe it's a newbie question, but I still can't find out why this
> happens..
> I managed to create simple IndexController and ErrorController, but I
> can't make ZF to render another script than index.phtml from indexAction
> of IndexController.
> What I need is to show a login form in case that user is not logged in.
> Here's the code:
> 
> <?php
> /*
>  * Default controller for back-end
>  * 
>  * Shows the back-end's homepage in case that user is logged in.
>  * Otherwise, it shows the login page. 
>  * @author Richard VĂ­tek <[EMAIL PROTECTED]>
>  */
> class IndexController extends Zend_Controller_Action
> {
>       /**
>        * Initialization - invoked in constructor.
>        */
>       public function init ()
>       {
>               //$this->view->addHelperPath('../application/views/helpers',
> 'Venturia_View_Helper');
>               $this->view->wwwroot = $this->_request->getBaseUrl();
>       }
> 
> 
>       /**
>        * The default action - show the home page.
>        */
>       public function indexAction ()
>       {
>               echo 'Index action called.';
>               $oUserSession = new Zend_Session_Namespace('user');
>               $oUserSession->id = 1;
>               unset($oUserSession->id);
>               //print_r($_SESSION);
>               //echo $this->_request->getHeader('accept-language');
>               $this->view->iUserId = $oUserSession->id;
>               $this->view->sBaseUrl = $this->_request->getBaseUrl(); //.
> $this->_request->getPathInfo();
>               
>               //user is not logged in => show login page
>               //if (!isset($oUserSession->id))
>               //{
>                       //echo 'Script Path:' . 
> $this->view->getScriptPath('login.phtml');
>                       $this->view->render('login.phtml', null, false);
>                       //echo 'Login';
>               //}
>       }
> }
> ?>
> 
> The render() method does not seem to be working as claimed in manual.
> a) script filename must be set with extension too
> b) AFAIK, login.phtml should be looked for in
> somepath/views/scripts/index/login.phtml, but it is looked for directly in
> somepath/views/scripts/ directory (controller's name not used, no matter
> how the 3rd parameter of render() method is set)
> c) and the worst, even when set unconditianally as seen in code above, it
> still renders somepath/views/scripts/index/index.phtml script instead of
> login.phtml
> 
> Can anyone explain me please why this happen and even better how to make
> it work?
> Thank a lot
> 

-- 
View this message in context: 
http://www.nabble.com/Strange-Zend_View-%3Erender%28%29---tf4872248s16154.html#a13946036
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to