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=.