Hello everybody!
I’am trying to do an authorization in my Yii application.
In my database I have the authData table which contains 2 primary key:
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;
In my Authdata model I override the primaryKey() method:
public function primaryKey()
{
return array('idauthData', 'employee_idEmployee');
}
But when I trying to find a row in Authdata activeRecord class using findByPk() method I`am getting an exception:
private function getModel(){
if (!$this->isGuest && $this->_model === null){
$this->_model = Authdata::model()->findByPk(array($this->id), array('select' => 'role'));
}
return $this->_model;
}
The exception has next description:
The value for the column "idauthData" is not supplied when querying the table "authdata".
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 ?>
And I don`t know how to resolve this problem.
I know that this is a simple mistake and I just miss some moment. That why if somebody could help me I will be very glad!
Thanks in advance