我试图在我的Yii应用程序中执行授权。 在我的数据库中,我有一个包含2主键的authData表:查询表“authdata”时不提供列值“idauthdata”
CREATE TABLE IF NOT EXISTS `authdata` (
`idauthData` int(11) NOT NULL AUTO_INCREMENT,
`login` varchar(45) NOT NULL,
`password` varchar(80) NOT NULL,
`role` varchar(45) NOT NULL,
`email` varchar(60) NOT NULL,
`employee_idEmployee` int(11) NOT NULL,
PRIMARY KEY (`idauthData`,`employee_idEmployee`),
UNIQUE KEY `idauthData_UNIQUE` (`idauthData`),
KEY `fk_authData_employee1_idx` (`employee_idEmployee`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
在我的authData模型我重写的PrimaryKey()方法:
public function primaryKey()
{
return array('idauthData', 'employee_idEmployee');
}
但是,当我试图找到一个排使用findByPk()方法获得I`am一个异常的authData ActiveRecord类:
private function getModel(){
if (!$this->isGuest && $this->_model === null){
$this->_model = Authdata::model()->findByPk(array($this->id), array('select' => 'role'));
}
return $this->_model;
}
异常有下一个描述: 查询表“authdata”时不提供列“idauthData”的值。
C:\xampp\htdocs\helloworld\protected\components\WebUser.php(14): CActiveRecord->findByPk(array("15"), array("select" => "role"))
09 }
10 }
11
12 private function getModel(){
13 if (!$this->isGuest && $this->_model === null){
14 $this->_model = Authdata::model()->findByPk(array($this->id), array('select' => 'role'));
15 }
16 return $this->_model;
17 }
18 }
19 ?>
而我不知道如何解决这个问题。 我知道这是一个简单的错误,我只是错过了一些时刻。那为什么如果有人能帮助我,我将会非常高兴! 在此先感谢
也许添加此列'select'阵列? – 2013-10-31 11:33:18
不好意思,我应该在哪里做? – Tequila
'$ this - > _ model = Authdata :: model() - > findByPk(array($ this-> id),array('select'=> array('role','idauthData')));'哦,并选择值应该是数组 – 2013-10-31 12:15:48