IMO, you should follow Cake conventions and use the callbacks the way they're intended (and are named). If the callback is "beforeRender" then obviously you wouldn't want to render from there. Just like if you tried to force "beforeRender" code into "afterRender", you're going to run into problems--and confuse other people who look at the code.
The most obvious solution IMO, would be just to set a controller property (e.g. $this->viewFile = $file_path), and then call render($this->viewFile) at the end of each action. You could also change $this->action to $file_path, but that may have other unintended consequences. You can also disable autoRender and then do the rendering in afterFilter(), but that's also breaking conventions and confusing. Lastly, you could overload the render() function and just replace it with the code you're putting in beforeRender(), using parent::render() to call the original render function. On May 26, 6:19 am, TuteC <[email protected]> wrote: > Hi all. I'd like to change the default action to render so as to check > if a customized one exists (so as to render page.eng.ctp instead of > page.ctp. So, if that file exists, I want to render it on > beforeRender(), like so: > > function beforeRender() { > $locale = $this->Session->read('Config.language'); > $file_path = VIEWS . $this->viewPath . DS . > $this->passedArgs[0] . ". > $locale.ctp"; > if (file_exists($file_path)) { > $this->render($file_path); > } > } > > Te problem is that render() calls beforeRender, and I begin an > infinite loop. Is there another way to replicate the behavior I want? > If not, should we have a render() which doesn't call beforeRender > (again), or an option so as to avoid it? > > My quick-and-dirty fix consisted in a duplicated render() function > without that call, but I think a better fix would be great for > CakePHP. > > Kind regards, > > Eugenio. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
