Php Yii$这在模型中不起作用
我是Yii的新手,我有一个小问题,但无法解决。问题是,当我在我的一个模型(活动记录)中调用Yii时,$this->attributes='something';我收到错误“Property”SiteController。未定义属性 我有一个控制器:Php Yii$这在模型中不起作用,php,object,activerecord,yii,Php,Object,Activerecord,Yii,我是Yii的新手,我有一个小问题,但无法解决。问题是,当我在我的一个模型(活动记录)中调用Yii时,$this->attributes='something';我收到错误“Property”SiteController。未定义属性 我有一个控制器: public function actionIndex() { // Create new clients active record $client = new Clients; // Check if user send
public function actionIndex()
{
// Create new clients active record
$client = new Clients;
// Check if user send some request
if (isSet($_POST)){
switch($_POST["action"]){
case 'newClient':
$registered = $client::addClient($_POST);
}
}
// render the view
$this->render('landing',array(
// Objects
'client' => $client,
// Variables
'registered' => $registered,
));
return true;
}
在模型中:
public function addClient($data){
// Set data
$this->attributes = $data["Clients"];
$this->password = self::generatePassword(6);
// Proceed
$this->setScenario('insert');
return true;
}
这些函数当然不完整,但这就是我得到错误的地方。我到底做错了什么?谢谢您正在以静态方法调用函数
$registed=$client::addClient($\u POST)代码>
应该是
$registered = $client->addClient($_POST);
当这样的事情发生在我身上时,我会选择dump()。也许这不是你想象的那样
否则我建议检查Yii生成的代码。几乎不熟悉该框架,但请检查您或您的IDE是否没有弄乱任何C风格的注释。检查打字错误、代码、元、表格。还要检查并确保没有同名的实体,SiteController
听起来有点通用