Question

I have just upgraded from CakePHP 1.3 to cakePHP 2.4.5.

I am getting the following error:

Fatal Error
Error: Call to a member function parseAccept() on a non-object  
File: /myapp/lib/Cake/Controller/Component/RequestHandlerComponent.php  
Line: 157

I'm not calling the function parseAccept() anywhere within my controller, and so don't understand why I am getting this error.

Was it helpful?

Solution

From the Cake Manual

Controller’s constructor now takes two parameters. A CakeRequest, and CakeResponse objects. These objects are used to populate several deprecated properties and will be set to $request and $response inside the controller.


The Fix:

Change your constructor signature..

From:

function __construct()
{
    parent::__construct();
}

To:

// Pass through the request and response objects 
// AND declare the visibility of the method
public function __construct($request = null, $response = null)
{
    parent::__construct($request, $response);
}

This should resolve your Error: Call to a member function parseAccept() on a non-object .

The official Cake 2.x docs for this issue can be found here:

http://book.cakephp.org/2.0/en/appendices/2-0-migration-guide.html#controller

If you have just upgraded from 1.x to 2.x, I would highly recommend you read through the detailed migration guides provided by cakePHP.

Migration Guides

2.0 Migration Guide
2.1 Migration Guide
2.2 Migration Guide
2.3 Migration Guide
2.4 Migration Guide

OTHER TIPS

In Cakephp 2.x The AppController's __contruct() has two objects. CakeRequest and Cake Response. You need to pass to the parent contruct

   public function __construct($request = null, $response = null) {
        parent::__construct($request, $response);
           //you code here
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top