سؤال

According to http://book.cakephp.org/2.0/en/models/behaviors.html#creating-behavior-methods,

I can do the following:

public function fly(Model $Model, $from, $to) {
    // Do some flying.
}

I want to have a passed-by-reference parameter in the behavior method.

This is my method:

public function extractByFields(Model $model, $data, $options = array(), Array $missingFields) {

the parameter I want to be passed by reference is $missingFields.

Reason is because I want to return my $foundFields but in case there are any other missing fields, I also want to expose them to the method caller.

If CakePHP cannot allow me to return passed-by-reference parameters in my behavior methods, I would like some advice on how best to have a workaround?

My version is CakePHP2.4

هل كانت مفيدة؟

المحلول

With behavior methods you cannot use pass-by-reference parameters. call_user_func_array() is used to call the methods and the arguments are not passed by reference.

Possible workaround: store missing fields in the Behavior class as an attribute and have a method to retrieve them.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top