Aja*_*tel 0 php cakephp cakephp-1.3
我正在 CakePHP 中创建一个登录身份验证应用程序,并收到此致命错误:在第 5 行的 /var/www/cakephp1/app/Controller/users_controller.php 中的非对象上调用成员函数allow()
这是我的控制器代码 users_controller.php
<?php
class UsersController extends AppController {
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('add');
}
public function add() {
if (!empty($this->data)) {
$this->User->create();
if ($this->User->save($this->data)) {
$this->Session->setFlash('User created!');
$this->redirect(array('action'=>'login'));
} else {
$this->Session->setFlash('Please correct the errors');
}
}
$this->set('groups', $this->User->Group->find('list'));
}
public function login() {
}
public function logout() {
$this->redirect($this->Auth->logout());
}
public function dashboard() {
$groupName = $this->User->Group->field('name',
array('Group.id'=>$this->Auth->user('group_id'))
);
$this->redirect(array('action'=>strtolower($groupName)));
}
public function user() {
}
public function administrator() {
}
public function manager() {
}
}
?>
Run Code Online (Sandbox Code Playgroud)
应用程序控制器.php
<?php
class AppController extends Controller {
public $components = array(
'Acl',
'Auth' => array(
'authorize' => 'actions',
'loginRedirect' => array(
'admin' => false,
'controller' => 'users',
'action' => 'dashboard'
)
),
'Session'
);
}
?>
Run Code Online (Sandbox Code Playgroud)
查看登录.ctp
<?php
echo $this->Form->create(array('action'=>'login'));
echo $this->Form->inputs(array(
'legend' => 'Login',
'username',
'password',
'remember' => array('type' => 'checkbox', 'label' => 'Remember me')
));
echo $this->Form->end('Login');
?>
Run Code Online (Sandbox Code Playgroud)
我正在使用 CakePHP 版本 1.3
1.解决方案:您需要做的就是在UsersController中添加以下行:
public $components = array('Auth');
Run Code Online (Sandbox Code Playgroud)
或者
2.解决方案:在UsersController中:
App::uses('AppController', 'Controller');
class UsersController extends AppController {
}
Run Code Online (Sandbox Code Playgroud)
然后在AppController中:
public $components = array('Auth');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15587 次 |
| 最近记录: |