Monday, November 22, 2010

Re: reference parameters in behaviour functions - references not working?

On Sun, Nov 21, 2010 at 6:24 AM, Tonu Tusk <lvotusk@googlemail.com> wrote:
> Hi guys, I'm not sure if I am doing something wrong, or if this is a
> bug caused by the magic of a the instance of a model getting inserted
> into underlying behaviour calls..
>
> I'd rather not post real code on here, but have included a specific
> enough example to try to re-enact the problem.
>
> basically, I have a behaviour with a function
>
> function behaviourFunction(&$i_Model, &$o_SomeDataOut)
> {
>   $o_SomeDataOut = 'Data From behaviourFunction';
>   return true;
> }


You don't have to pass the data. You're dealing with objects, so just
make the data a member of the object. Since the object instance is
passed to the behavior's method (look into
BehaviorCollection::dispatchMethod) you have access to the data as
well.

function behaviorMethod(&$Model)
{
$Model->someVar = 'foo';

return true;
}

Simple as that.

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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

No comments: