【发布时间】:2012-02-06 14:58:02
【问题描述】:
我正在 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() {
}
}
?>
app_controller.php
<?php
class AppController extends Controller {
public $components = array(
'Acl',
'Auth' => array(
'authorize' => 'actions',
'loginRedirect' => array(
'admin' => false,
'controller' => 'users',
'action' => 'dashboard'
)
),
'Session'
);
}
?>
查看login.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');
?>
我使用的是 CakePHP 1.3 版
【问题讨论】:
-
您的 App Controller 在 app/ 目录中是否像在 Cake1.3 中一样?
-
@Dave 是的,它在 cake1.3 中
-
而且你的 AppController 文件在 app/ 目录下,而不是 app/controllers 目录下,是吗?
标签: php cakephp cakephp-1.3