CakePHP PaginationRecallComponent, Strict (2048): Declaration of PaginationRecallComponent::initialize()

假装没事ソ 提交于 2019-12-02 08:41:15

问题


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

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

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


回答1:


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

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

public function initialize(Controller $controller)

whereas in the PaginationRecallComponent it is:

function initialize(&$controller)

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.



来源:https://stackoverflow.com/questions/20186038/cakephp-paginationrecallcomponent-strict-2048-declaration-of-paginationrecal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!