在模型CakePHP中访问控制器变量 [英] accessing controller variables in model CakePHP

查看:109
本文介绍了在模型CakePHP中访问控制器变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在CakePHP的控制器中有两个变量,可以使用

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???

推荐答案

您没有指定为什么在模型中需要这些变量。因为上下文对于这类问题非常重要,所以如果没有它,很难准确回答。

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'];






问候,
Hiawatha


Regards, Hiawatha

这篇关于在模型CakePHP中访问控制器变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆