Im wondering how I can set some variables in my controller, and then be开发者_开发百科 able to access them in my model and a behaviour for that model.
I have tried the below, but with no luck: in controller: $this->Model->data['foo']="bar"; in behaviour: $Model->data['foo'];
Grateful for any help!
One way to pass data is through user-defined functions in your model.
For example,
$flag = $this->Model->checkIntegrity($this->data);
In the Model,
function checkIntegrity($data) {
...
}
You could also pass them in as a reference if you wish to make direct changes to the data:
function checkIntegrity(&$data) {
...
}
It depends on what kind of data you're trying to pass around. If it's model/behavior settings you could use class properties. Example:
In model or behavior:
public $custom_variable = null; // or other default value
In controller:
$this->Model->custom_variable = 'new value';
or
$this->Behavior->custom_variable = 'new value';
精彩评论