CakePHP错误:调用非对象上的成员函数parseAccept() [英] CakePHP Error: Call to a member function parseAccept() on a non-object

查看:249
本文介绍了CakePHP错误:调用非对象上的成员函数parseAccept()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚从 CakePHP 1.3 升级至 cakePHP 2.4.5



我得到以下错误:

 致命错误
错误:对非对象的函数parseAccept()
文件:/myapp/lib/Cake/Controller/Component/RequestHandlerComponent.php
行:157

我不是在我的控制器中的任何地方调用函数 parseAccept(),所以不明白为什么我收到此错误。

解决方案

从蛋糕手册




控制器的构造函数现在有两个参数。 CakeRequest和
CakeResponse对象。这些对象用于填充多个
不推荐的属性,并将
中的$ request和$ response设置为控制器。







修正:



更改您的构造函数签名..



从:



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

收件人

  //通过请求和响应对象
//并声明方法的可见性
public function __construct($ request = null,$ response = null)
{
parent :: __ construct($ request,$ response);
}

这应该可以解决您的错误:

官方 Cake 2.x docs 可以在这里找到:



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



如果您刚刚从 1.x 升级到 2.x ,我强烈建议您阅读 cakePHP 提供的详细迁移指南。



迁移指南



2.0迁移指南

2.1移转指南

2.2迁移指南

2.3迁移指南

2.4迁移指南


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.

解决方案

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

这篇关于CakePHP错误:调用非对象上的成员函数parseAccept()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆