I don't entirely understand why moving the target action from private to protected or public results in the $viewVars being set or not set ?
On Mon, Sep 28, 2009 at 5:05 PM, brian <[email protected]> wrote: > > OK, I suppose that wasn't very clear. What I was getting at is that, > if calling setAction(), the target action must have either public or > protected access. > > On Sun, Sep 27, 2009 at 11:20 PM, Martin Radosta > <[email protected]> wrote: > > > > On 09/27/2009 04:31 PM, brian wrote: > >> The comment for setAction() says that it "Internally redirects one > >> action to another." However, it doesn't really *redirect* so much as > >> simply call the action using call_user_func_array(). It amounts to > >> about the same thing, more or less, but there's something to keep in > >> mind: > >> > >> public function someAction() > >> { > >> $this->setAction( > >> 'error', > >> 'This error message should display.', > >> array('foo' => 'bar') > >> ); > >> } > >> > >> private function error($msg = '', $data = array()) > >> { > >> $this->set(compact('msg', 'data')); > >> } > >> > >> This will display the error view *but* the $viewVars will not be set. > >> In order to make this work, set the access to the called action to > >> protected (or public, obviously), because setAction() is defined in > >> the parent class (Controller). If you absolutely need it to be > >> private, you'll have to override setAction() in your own controller. > >> > > Don't know if I understand "exactly" your problem, but maybe an > > auxiliary function should do the job: > > > > public function someAction() { > > $this->setVars('varA', 'varB', 'varN'); > > $this->setAction('error'); > > } > > > > private function error() { > > $this->set('vars', $this->getVars()); > > } > > > > Hope this helps... > > > > MARTIN > > > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ 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=en -~----------~----~----~----~------~----~------~--~---
