-- Nogyara <[EMAIL PROTECTED]> wrote (on Sunday, 25 November 2007, 04:32 PM -0800): > 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: >
<snip> > //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); Don't call render() on the view object. Call render() on the controller object ($this) or the viewRenderer (Zend_Controller_Action::render() actually proxies to the viewRenderer, which in turn proxies to the view object, after first doing some other work): $this->render('login'); This will do several things for you: * notice you don't need the file suffix * look for the view script in the subdirectory named after the current controller * tell the view renderer not to render any other views In other words, the above correction to your code will answer all of your questions below. Typically, the only interaction with the view object you need in your controller is to set variables; otherwise, use the controller's 'render() convenience method, or go through the viewRenderer. > 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? -- Matthew Weier O'Phinney PHP Developer | [EMAIL PROTECTED] Zend - The PHP Company | http://www.zend.com/