2

该项目是使用 CakePHP-1.3 开发的

现在我正在尝试升级到 CakePHP-2.0

我已经使用 CakePHP-2.0 约定重命名了所有控制器和模式。

现在,如果我重新加载页面,我会收到如下错误:

Indirect modification of overloaded property PostsController::$Auth has no effect [APP/Controller/PostsController.php, line 11]

编码:

帖子控制器:

$this->Auth->allowedActions =
        array('index','view','archive','listarchive','viewfromcategory','tags','aboutme','contact','polls');

应用控制器:

class AppController extends Controller {
    var $components = array('Acl', 'Session', 'Auth','RequestHandler');
    //var $helpers = array('Html', 'Form','Js','Session','Cache');
    var $helpers = array('Html', 'Form','Js','Session');

    function beforeFilter() {
        //Configure AuthComponent           
        $this->Auth->actionPath = 'controllers/';

        $this->Auth->allowedActions = array('display');

        //$this->Auth->authorize = 'actions';
        $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
        $this->Auth->logoutRedirect = array('controller' => 'posts', 'action' => 'index');
        $this->Auth->loginRedirect = array('controller' => 'posts', 'action' => 'index');
    }

我该如何解决这个问题?

4

2 回答 2

3

Cake 2.0 迁移指南中所述:

认证组件

AuthComponent 在 2.0 中完全重构,这样做是为了帮助减少开发人员的困惑和挫败感。此外,AuthComponent 变得更加灵活和可扩展。您可以在身份验证指南中找到更多信息。

由于 cakephp 核心的更改,您会收到该错误,因此您应该根据新指南调整您的代码。

我在修改控制器内的数据数组时遇到了同样的问题:

$this->data['foo'] = 'bar';

并且不得不切换它以使用新的 CakeRequest 对象:

$this->request->data['foo'] = 'bar';
于 2011-10-21T07:01:30.277 回答
1

要修复警告,您可以尝试以下操作:

在您的“PostsController”中替换:

$this->Auth->allowedActions =
    array('index','view','archive','listarchive','viewfromcategory','tags','aboutme','contact','polls');

经过

$this->Auth->allow(array('index','view','archive','listarchive','viewfromcategory','tags','aboutme','contact','polls'));
于 2011-10-25T16:49:48.160 回答