accessing controller variables in model CakePHP

我的未来我决定 提交于 2019-12-11 07:38:24

问题


I have two variables in my controller in CakePHP which are accessed using

$this->data['General']['q']

$this->data['General']['typesearch'].

How Do I refer to these variables in the model???


回答1:


You didn't specify why do you need those variables in your model. Because the context is very important for this kind of questions, it's hard to accurately answer the one without it.

Well, you could try defining variables in your model first:

Class MyModel Extends AppModel {
    var $q;
    var $typesearch;
}

Then, in your controller you could try to pass the values of controller variables to those variables:

$this->MyModel->q = $this->data['General']['q'];
$this->MyModel->typesearch = $this->data['General']['typesearch'];

Regards, Hiawatha



来源:https://stackoverflow.com/questions/10987489/accessing-controller-variables-in-model-cakephp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!