CakePHP PaginationRecallComponent, Strict (2048): PaginationRecallComponent::initialize() 的声明 [英] CakePHP PaginationRecallComponent, Strict (2048): Declaration of PaginationRecallComponent::initialize()

查看:28
本文介绍了CakePHP PaginationRecallComponent, Strict (2048): PaginationRecallComponent::initialize() 的声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试插入 PaginationRecallComponent (http://bakery.cakephp.org/articles/Zaphod/2012/03/27/paginationrecall_for_cakephp_2_x),在

I have tried to insert PaginationRecallComponent (http://bakery.cakephp.org/articles/Zaphod/2012/03/27/paginationrecall_for_cakephp_2_x), in

App -> 控制器 -> 组件 -> PaginationRecallComponent.php

App -> Controller -> Component -> PaginationRecallComponent.php

用户控制器:public $components = array('PaginationRecall');

UserController: public $components = array('PaginationRecall');

为什么我收到以下错误:

Why I received the following error:

Strict (2048): Declaration of PaginationRecallComponent::initialize() should be compatible with Component::initialize(Controller $controller) [APP/Controller/Component/PaginationRecallComponent.php, line 46]
Code Context


App::load() - CORE/Cake/Core/App.php, line 567
App::load() - CORE/Cake/Core/App.php, line 567
spl_autoload_call - [internal], line ??
class_exists - [internal], line ??
ComponentCollection::load() - CORE/Cake/Controller/ComponentCollection.php, line 110
ComponentCollection::init() - CORE/Cake/Controller/ComponentCollection.php, line 53
Controller::constructClasses() - CORE/Cake/Controller/Controller.php, line 652
Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 183
Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 162
[main] - APP/webroot/index.php, line 97

CakePHP 2.4.2

CakePHP 2.4.2

推荐答案

出现此错误是因为 PaginationRecallComponent 类中的 initialize 方法的签名与一个在它的父类中.

You get this error because the signature of the initialize method in the PaginationRecallComponent class is different from the one in its parent class.

如果您查看代码,您会看到 Cake/Controller/Component.php 中的签名是:

If you look at the code you will see that in Cake/Controller/Component.php the signature is:

public function initialize(Controller $controller)

而在 PaginationRecallComponent 中是:

function initialize(&$controller)

在第一种情况下,$controller 参数必须是 Controller 的实例,而在第二种情况下则没有这样的约束.要消除错误,您只需将此约束添加到 PaginationRecallComponentinitialize 方法的签名中.

In the first case the $controller parameter must be an instance of Controller, whereas in the second case there is no such constraint. To get rid of the error you simply have to add this constraint to the signature of the initialize method of the PaginationRecallComponent.

这篇关于CakePHP PaginationRecallComponent, Strict (2048): PaginationRecallComponent::initialize() 的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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