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

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

问题描述

我尝试插入PaginationRecallComponent( http://bakery.cakephp 。

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

应用程序 - >控制器 - >组件 - > PaginationRecallComponent.php

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

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

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

为什么我收到错误:

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 类中的初始化方法不同于其父类中的方法。

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 的实例,而在第二种情况下没有这样的约束。为了摆脱这个错误,你只需要将这个约束添加到 PaginationRecallComponent initialize 方法的签名。

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):分页声明DeclareComponent :: initialize()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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