Reputation: 71
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!
Upvotes: 0
Views: 1603
Reputation: 1
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';
Upvotes: 0
Reputation: 6340
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) {
...
}
Upvotes: 1