Yii アプリケーションで認証を行おうとしています。私のデータベースには、2 つの主キーを含む authData テーブルがあります。
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() メソッドを使用して 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 ?>
そして、この問題を解決する方法がわかりません。これは単純な間違いであることはわかっています。誰かが私を助けることができれば、私はとてもうれしいです! 前もって感謝します