To be clear that would always load for requests with a json extension:

app/views/shared/json.ctp

On Nov 22, 6:58 pm, Amit <[email protected]> wrote:
> What if you just override the action?
>
> funciton beforeRender() {
>         if ($this->RequestHandler->ext == 'json') {
>                 $this->real_action = $this->action;
>                 $this->action = "json";
>                 $this->viewPath = "shared";
>         }
>
> }
>
> function afterRender(){
>         if ($this->RequestHandler->ext == 'json') {
>                 $this->action = $this->real_action;
>         }}
>
> On Nov 22, 5:30 pm, ddaffy <[email protected]> wrote:
>
>
>
> > sure, i can do that, and it works really fine. but problem is, if you
> > read first post, i need a way to do this on all actions, in
> > AppController or SomeController, depending on extension (.json in this
> > case).
>
> > On Nov 22, 4:14 pm, Dave <[email protected]> wrote:
>
> > > You just call it right from the action
>
> > > On Sun, Nov 22, 2009 at 9:39 AM, ddaffy <[email protected]> wrote:
> > > > thanks for replies guys. :)
>
> > > > i came to a conclusion that i can't use render() function for this
> > > > purpose. reason is there are three callbacks i could place this call
> > > > in:
> > > > - AppController::beforeFilter() - won't work because it's called
> > > > before action
> > > > - AppController::beforeRender() - won't work because it'll go into
> > > > infinite loop (render() calls beforeRender())
> > > > - AppController::afterFilter() - won't work because rendering is
> > > > already done
>
> > > > only thing i see, that would solve this, is that some variable which
> > > > would specify name of view file is added to controller (like $layout),
> > > > and used in render() action to determine view file. if some other
> > > > solution doesn't come up, i'll post feature request. maybe i get
> > > > lucky. :)
>
> > > > cheers
>
> > > > On Nov 19, 8:25 am, David Roda <[email protected]> wrote:
> > > > > Last response I promise!
>
> > > > > I read the whole post this time... If you want to change the view 
> > > > > that is
> > > > > rendered for an action you can manually call $this->render .  Also the
> > > > > target action can be tested for with $this->action if you need to test
> > > > for
> > > > > specific cases.
>
> > > > > On Thu, Nov 19, 2009 at 2:22 AM, David Roda <[email protected]>
> > > > wrote:
> > > > > > 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]
> > > > > >>>  om>
> > > > <cake-php%[email protected] om>
> > > > > >>> .
> > > > > >>> 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]<cake-php%[email protected]
> > > >  om>
> > > > .
> > > > 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=.


Reply via email to