简体   繁体   中英

Can't upgrade the project to CakePHP-2.0

The project was developed with CakePHP-1.3

Now I'm trying to upgrade to CakePHP-2.0

I have renamed all controllers and mode with the CakePHP-2.0 conventions.

Now if I reloads the page I got error like this:

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

The code:

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

How can I fix this problem?

As mentioned in the Cake 2.0 migration guide :

AuthComponent

The AuthComponent was entirely re-factored for 2.0, this was done to help reduce developer confusion and frustration. In addition, AuthComponent was made more flexible and extensible. You can find out more in the Authentication guide.

You are getting that error because of the changes to the cakephp core, so you should adjust your code according to the new guides.

I have encountered the same issue when modifying the data array inside the controller:

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

and had to switch this to use the new CakeRequest object:

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

To fix warning you can try follow:

In your "PostsController" replace:

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

By

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM