我如何使用以下內容。 我有列在我的表wf_users:wf_username, wf_password
現在在我的形式我不想要任何人瑟我的表結構,因此我在表單中使用CakePHP 2.0 AuthComponent使用自己的列名稱
$this->Form->input("username");
而不是$this->Form->input("wf_username");
我的帖子是這樣
User=>array('username', 'password');
現在我需要他們改變了我的指定的列或想要做的伎倆在允許的地區登陸,因爲它try's與錯列不取(用)。
我的AppController:
class AppController extends Controller {
public $viewClass = 'Theme';
public $theme;
public $components = array(
'Auth'=> array(
'loginRedirect'=>array('controller'=>'users', 'action'=>'dashboard'),
'logoutRedirect'=>array('controller'=>'users', 'action'=>'dashboard'),
'authError'=>'yout can´t access the page!',
'authorise'=>array('Controller'),
#'authenticate' => array(
# 'Form' => array(
# 'fields' => array(
# 'wf_auth_user_username' => 'username',
# 'wf_auth_user_password' => 'password'
# )
# )
#)
),
'Session'
);
//Before mainlayout
public function beforeFilter() {
parent::beforeFilter();
$this->theme = 'SM';
$this->Auth->fields = array('username'=>'wf_auth_user_username','password'=>'wf_auth_user_password');
//Configure AuthComponent
$this->Auth->allow('*');
//Logged in user
$this->set('isauth', 'loggedout'); //$this->userpanelAuth());
}
public function isAuthorized($user) {
return true;
}
protected function userpanelAuth() {
if($this->isAuthorized()) {
return 'loggedin';
}else{
return 'loggedout';
}
}
}
,這是我的方式:
<div id="display-panel">
<?
echo $this->Session->flash();
echo $this->Form->create('User', array('action' => 'login'));
echo $this->Form->input(
'username',
array('label'=>false, 'div'=>false,'placeholder'=>'Benutzername',''));
echo $this->Form->input(
'password',
array('label'=>false, 'div'=>false,'placeholder'=>'Passwort'));
echo $this->Form->end(array('label'=>'login','div'=>false));
?>
</div>
it's不工作,每次我得到這個,當我試圖 錯誤:SQLSTATE [42S22]:列未發現:在1054未知列'User.username「where子句」 ,因爲它再次嘗試它取用發佈到控制器的用戶名,而不是用我的wf_username ... 我在AppController的方法「beforeFilter」下設置它你如何解釋 – webfacer
在用戶控制器中,如果你有一個beforeFilter方法,你需要確保在那裏有'parent :: __ beforeFilter()',否則AppController方法將不會運行 – Stoosh
道歉,看起來像Cake已經改變了2.0版的Auth語法,請參閱下面的brism的回答 – Stoosh