开发者

Make a variable in app_controller access in app_model

开发者 https://www.devze.com 2023-04-01 10:00 出处:网络
In my cakephp application I have some logic in beforeFilter method in app_controller.php which picks up a value.

In my cakephp application I have some logic in beforeFilter method in app_controller.php which picks up a value.

function beforeFilter(){
    $this->oCurrentOrganisation = $organisation["Organisation"];
}

In this manner the property oCurrentOrganisation is accessible in all controllers.

I require to use this value from within the beforeSave in the app_model.php ... what is the best way to pass the variable's value.

开发者_如何学JAVA

Thanks

Regards Gabriel


does this logic have to be in beforeRender()? this is quite late to save to the model. one would need more details on what you are trying to achieve.

but either way you can always pass on stuff to the model like so

$this->Model->customVar = 'foo';

or via method (and assign the content to a variable)

$this->Model->customMethod('foo');

if you do that before save() you can count on it in beforeSave().

0

精彩评论

暂无评论...
验证码 换一张
取 消