Re: change action to render on beforeRender()
Yea, if you could keep the view files in subdirectories instead of giving them different filenames, that would be optimal. On May 27, 3:26 am, "Dr. Loboto" wrote: > Just add var like hasRendered, set and check it in beforeRender. > > Or keep customized views inside subfolders and just alter $this- > > >viewPath in beforeRender. I think it's much better. > > On May 26, 8:19 pm, TuteC 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() 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 cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: change action to render on beforeRender()
Just add var like hasRendered, set and check it in beforeRender. Or keep customized views inside subfolders and just alter $this- >viewPath in beforeRender. I think it's much better. On May 26, 8:19 pm, TuteC 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() 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 cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: change action to render on beforeRender()
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 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 cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
change action to render on beforeRender()
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 cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en