无法将项目升级到CakePHP-2.0

时间:2011-10-20 23:29:17

标签: php cakephp upgrade cakephp-2.0

该项目是用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]

代码:

PostsController:

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

AppController的:

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');
    }

如何解决此问题?

2 个答案:

答案 0 :(得分:3)

Cake 2.0 migration guide中所述:

  

AuthComponent

     

AuthComponent完全被重新考虑了2.0,这是完成的   帮助减少开发人员的困惑和挫败感。此外,   AuthComponent变得更加灵活和可扩展。你可以找到   更多信息请参见Authentication指南。

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

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

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

并且必须将其切换为使用新的CakeRequest对象:

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

答案 1 :(得分: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'));