Re: Controller::setAction heads-up

2009-09-29 Thread Bert Van den Brande
On Tue, Sep 29, 2009 at 4:14 PM, brian  wrote:

>
> On Tue, Sep 29, 2009 at 2:19 AM, Bert Van den Brande 
> wrote:
> > Ok tnx now I understand the problem, though I still can't wrap my head
> > around the core issue.
> >
> > Is it that call_user_func_array() can never call private methods ? I
> found
> > some comments here and there on the web stating that the new Reflection
> API
> > will solve this, but nothing concrete on calling private methods ...
> >
> > As far as I can tell it can't be an OO issue, since
> TransactionsController
> > will inherit the setAction() method from Controller ... therefore calling
> > setAction() on an instance of TransactionsController should be allowed to
> > access the private method error() that is defined in the same
> > TransactionsController class.
> >
> > I love a good quiz now and then :)
>
> No, the parent cannot access private methods, although it seems
> somewhat counterintuitive. From the fine manual:
>
> -- snip --
> The visibility of a property or method can be defined by prefixing the
> declaration with the keywords public, protected or private. Class
> members declared public can be accessed everywhere. Members declared
> protected can be accessed only within the class itself and by
> inherited and parent classes. Members declared as private may only be
> accessed by the class that defines the member.
> -- snip --
>
> http://us2.php.net/manual/en/language.oop5.visibility.php
>
> >
>
Indeed you're right, programming in Smalltalk for a couple of months made my
OO skilz rusty, even though the method setAction() is inherited it is not
considered part of the TransactionsController class regarding the private
modifiers.

Thanks for the training ;)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Controller::setAction heads-up

2009-09-29 Thread brian

On Tue, Sep 29, 2009 at 2:19 AM, Bert Van den Brande  wrote:
> Ok tnx now I understand the problem, though I still can't wrap my head
> around the core issue.
>
> Is it that call_user_func_array() can never call private methods ? I found
> some comments here and there on the web stating that the new Reflection API
> will solve this, but nothing concrete on calling private methods ...
>
> As far as I can tell it can't be an OO issue, since TransactionsController
> will inherit the setAction() method from Controller ... therefore calling
> setAction() on an instance of TransactionsController should be allowed to
> access the private method error() that is defined in the same
> TransactionsController class.
>
> I love a good quiz now and then :)

No, the parent cannot access private methods, although it seems
somewhat counterintuitive. From the fine manual:

-- snip --
The visibility of a property or method can be defined by prefixing the
declaration with the keywords public, protected or private. Class
members declared public can be accessed everywhere. Members declared
protected can be accessed only within the class itself and by
inherited and parent classes. Members declared as private may only be
accessed by the class that defines the member.
-- snip --

http://us2.php.net/manual/en/language.oop5.visibility.php

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Controller::setAction heads-up

2009-09-28 Thread Bert Van den Brande
Ok tnx now I understand the problem, though I still can't wrap my head
around the core issue.

Is it that call_user_func_array() can never call private methods ? I found
some comments here and there on the web stating that the new Reflection API
will solve this, but nothing concrete on calling private methods ...

As far as I can tell it can't be an OO issue, since TransactionsController
will inherit the setAction() method from Controller ... therefore calling
setAction() on an instance of TransactionsController should be allowed to
access the private method error() that is defined in the same
TransactionsController class.

I love a good quiz now and then :)

On Mon, Sep 28, 2009 at 5:35 PM, brian  wrote:

>
> On Mon, Sep 28, 2009 at 11:20 AM, Bert Van den Brande 
> wrote:
> > 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 ?
>
> The first line in setAction() changes the controller's $action:
>
> $this->action = $action;
>
> Then, the last line of the method fails on call_user_func_array()
> because the given action is private:
>
> Warning (2): call_user_func_array()
> [http://php.net/function.call-user-func-array]: First argument is
> expected to be a valid callback, 'TransactionsController::error' was
> given [CORE_1.2.5/cake/libs/controller/controller.php, line 697]
>
> However, it's not a fatal error and the controller's $action has
> already been changed, so it's the view for this that is used in
> render() even though the action is never called.
>
> Anyway, it's not a Cake bug. I just wanted to post this for anyone
> else who might run into it.
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Controller::setAction heads-up

2009-09-28 Thread brian

On Mon, Sep 28, 2009 at 11:20 AM, Bert Van den Brande  wrote:
> 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 ?

The first line in setAction() changes the controller's $action:

$this->action = $action;

Then, the last line of the method fails on call_user_func_array()
because the given action is private:

Warning (2): call_user_func_array()
[http://php.net/function.call-user-func-array]: First argument is
expected to be a valid callback, 'TransactionsController::error' was
given [CORE_1.2.5/cake/libs/controller/controller.php, line 697]

However, it's not a fatal error and the controller's $action has
already been changed, so it's the view for this that is used in
render() even though the action is never called.

Anyway, it's not a Cake bug. I just wanted to post this for anyone
else who might run into it.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Controller::setAction heads-up

2009-09-28 Thread Bert Van den Brande
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  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
>  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 cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Controller::setAction heads-up

2009-09-28 Thread brian

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
 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 cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Controller::setAction heads-up

2009-09-27 Thread Martin Radosta

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 cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---