I'm sorry its late... I didn't even read your post... please ignore my reply! =(
On Thu, Nov 19, 2009 at 2:21 AM, David Roda <[email protected]> wrote: > I think you can use the RequestHandler component for this. > http://book.cakephp.org/view/174/Request-Handling > > > On Wed, Nov 18, 2009 at 10:31 PM, Dr. Loboto <[email protected]> wrote: > >> There is a hack to render view from other folder: $this->render >> ('..'.DS.'shared'.DS.'json'); >> >> On Nov 18, 6:13 pm, ddaffy <[email protected]> wrote: >> > hi! >> > >> > i'm using Router::parseExtensions('json') to be able to request data >> > delivered in json format, and i've been wondering if there's a way to >> > change view file that will be used to render data? >> > >> > if action test from Examples controller ( /examples/test ) is >> > requested, default view (app/views/examples/test.ctp) is rendered with >> > default layout (app/views/layouts/default.ctp). >> > >> > if /examples/test.json is requested app/views/examples/json/test.ctp >> > is rendered with app/views/layouts/json/default.ctp layout. >> > >> > because i use unified way for passing variables to view, i don't need >> > every action to have different view for json extension (app/views/ >> > examples/json/test1.ctp, app/views/examples/json/test2.ctp...), and i >> > would like to use e.g. app/views/shared/json.ctp. i know how to >> > achieve this for single action, but i need a way to do this globally >> > (in AppController). >> > >> > what i tried: >> > >> > funciton beforeRender() { >> > if ($this->RequestHandler->ext == 'json') { >> > $this->viewPath = 'shared'; >> > } >> > >> > } >> > >> > results in rendering app/views/shared/<action_name>.ctp >> > >> > funciton beforeRender() { >> > if ($this->RequestHandler->ext == 'json') { >> > $this->render('/shared/json'); >> > // or: $this->render('shared/json'); >> > // or: $this->render(null, null, '/shared/json'); >> > // or variations.. >> > } >> > >> > } >> > >> > result is empty. >> > >> > also i saw solution with creating new view class that will override >> > render function and customising it, but it sounds like overkill to >> > me.. >> > >> > ideal solution in addition to setting $viewPath ($this->viewPath = >> > 'shared') would be to change name of view file that will be requested >> > for rendering, but haven't found a way to do that. >> > >> > any ideas would be appreciated. >> > thanks. :) >> >> -- >> >> 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]<cake-php%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/cake-php?hl=. >> >> >> > -- 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=.
