我先从CakePHP 2.0开始,可以 past一 past。 这是我的法典:
<<>AppController>:
class AppController extends Controller
{
function beforeFilter()
{
$this->Auth->userModel = User ;
$this->Auth->fields = array( username => email , password => password );
$this->Auth->loginAction = array( controller => users , action => login );
$this->Auth->loginRedirect = array( controller => hotels , action => dashboard );
}
}
UsersController:
class UsersController extends AppController
{
var $name = Users ;
var $helpers = array( Html , Form );
var $components = array( Auth , Session );
function beforeFilter()
{
$this->Auth->allow("logout");
parent::beforeFilter();
}
function logout()
{
$this->redirect($this->Auth->logout());
}
function login()
{
if ($this->Auth->login())
{
$this->redirect($this->Auth->redirect());
} else
{
$this->Session->setFlash(__( Invalid username or password, try again ));
}
}
}
<>strong>login.ctp:
echo $this->Form->create(); // User , array( action => login ));
echo $form->Form->input( email );
echo $form->Form->input( password );
echo $form->Form->end( Login );
错误是:
Notice (8): Undefined variable: form [APPViewUserslogin.ctp, line 13]
Notice (8): Trying to get property of non-object [APPViewUserslogin.ctp, line 13]
Fatal error: Call to a member function input() on a non-object in E:proyectoswebswtappViewUserslogin.ctp on line 13
Any ideas? Thanks in advance!