amit, overriding render() function sounds just right, didn't tought of that.. :) thanks for the idea!
walther, thanks. saw that at the very start of my research of this problem, but as i said in the first post, sounds like an overkill to me. IMO, what i need should be as easy as setting some variable in controller. but i'll go with amit's proposal if it works (and i don't see why it wouldn't work), it's simple enough. On Nov 23, 6:40 am, Walther <[email protected]> wrote: > This:http://bakery.cakephp.org/articles/view/generating-automatized-json-a... > > is exactly what you are looking for. > > On Nov 18, 2: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]. For more options, visit this group at http://groups.google.com/group/cake-php?hl=.
