cakephp - CakePHP 在 null 上调用成员函数 error()
问题描述
我尝试修复 cakePHP 问题。cakePHP 版本是 2.10.10,我不想更新项目,因为我不想过度使用整个代码。我没有在 cakePHP 中创建应用程序并且我是新手,所以我只尝试修复错误。
我还添加了一个新用户以确保密码正确。当我尝试登录时,我收到此错误消息。
在 null 上调用成员函数 error()
Call to a member function error() on null
Error: An Internal Error Has Occurred.
Stack Trace
[internal function] → UsersController->manager_login()
CORE/Cake/Controller/Controller.php line 491 → ReflectionMethod->invokeArgs(UsersController, array)
CORE/Cake/Routing/Dispatcher.php line 193 → Controller->invokeAction(CakeRequest)
CORE/Cake/Routing/Dispatcher.php line 167 → Dispatcher->_invoke(UsersController, CakeRequest)
APP/webroot/index.php line 117 → Dispatcher->dispatch(CakeRequest, CakeResponse)
应用控制器.php
<?php
App::uses('Controller', 'Controller');
class AppController extends Controller {
public $components = array(
//'Flash',
'Session',
'Auth' => array(
'authorize' => array('Controller'),
'authenticate' => array(
'Form' => array(
'passwordHasher' => array(
'className' => 'Simple',
'hashType' => 'sha256'
)
)
),
'loginRedirect' => array('controller' => 'projekte', 'action'=> 'index', 'manager' => true),
'logoutRedirect' => array('controller' => 'users', 'action' => 'logout')
));
function beforeFilter() {
if (isset($this->params['prefix']) && $this->params['prefix'] == 'manager') {
$this->layout = 'admin';
}
}
function isAuthorized($user) {
return true;
}
}
用户控制器.php
<?php
class UsersController extends AppController {
var $name = 'Users';
function beforeFilter() {
parent::beforeFilter();
$this->layout = 'admin';
$this->Auth->allow('login', 'logout', 'add');
}
function index() {
$this->redirect(array('controller' => 'users', 'action' => 'login'));
}
function login() {
$this->redirect(array('controller' => 'users', 'action' => 'login', 'manager' => true));
}
function manager_login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirectUrl());
} else {
$this->Flash->error('Ungültige Zugangsdaten');
}
}
}
function logout() {
$this->Auth->logout();
$this->redirect(array('controller'=>'pages', 'action'=>'display', 'home', 'manager'=>false));
}
public function add() {
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->save($this->request->data)) {
$this->Flash->success(__('The user has been saved'));
return $this->redirect(array('action' => 'index'));
}
$this->Flash->error(
__('The user could not be saved. Please, try again.')
);
}
}
}
?>
解决方案
推荐阅读
- java - 使用正确的同步方式避免数据丢失
- azure - 如何使用 Azure CLI(az ad app)创建范围
- java - .java 使用或覆盖已弃用的 API。& 使用 -Xlint:deprecation 重新编译以获取详细信息
- javascript - 具有 Promises 的不同函数调用类型
- r - sub() 函数替换多个项目
- python - 如何按字段/字符串而不是按字符创建 csv.reader() 索引?
- java - setIconImage intellij 项目 javax.swing
- php - laravel LoginController 中的这个 traitLogout 函数
- c++ - Boost Signals2 将 Slot 传递给成员函数以进行断开连接
- devops - 在 Azure 数据工厂的链接服务中参数化集成运行时