我如何使用以下内容。
我的表格中有列wf_users:wf_username, wf_password
现在在我的表格中我不想让任何人看到我的表格结构因此我在我的表格中使用
$this->Form->input("username");
而不是$this->Form->input("wf_username");
我的帖子看起来像这样
User=>array( 'username', 'password' );
现在我需要将它们更改为我的命名列,或者想要在允许的区域中登录,因为它尝试使用错误的列进行提取("username"
不使用"wf_usernam"
)
我的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>
答案 0 :(得分:3)
Auth组件允许您在设置配置时指定不同的字段。在这种情况下,您使用的是Form
身份验证处理程序,该处理程序具有fields
密钥。
<?php
// Pass settings in $components array
public $components = array(
'Auth'=> array(
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email')
)
)
)
);
答案 1 :(得分:0)
设置所有Auth设置(通常在beforeFilter回调中)时,只需设置fields
属性
$this->Auth->fields = array('username' => 'wf_username', 'password' => 'wf_password');
答案 2 :(得分:0)
您不需要使用这些列名称,wf_。坚持惯例,不要浪费时间。