【问题标题】:CakePHP PaginationRecallComponent, Strict (2048): Declaration of PaginationRecallComponent::initialize()CakePHP PaginationRecallComponent, Strict (2048): PaginationRecallComponent::initialize() 的声明
【发布时间】:2013-12-09 18:20:02
【问题描述】:

我已尝试在

中插入 PaginationRecallComponent (http://bakery.cakephp.org/articles/Zaphod/2012/03/27/paginationrecall_for_cakephp_2_x)

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

用户控制器: 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 initialization components


    【解决方案1】:

    您收到此错误是因为 PaginationRecallComponent 类中的 initialize 方法的签名与其父类中的签名不同。

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

    public function initialize(Controller $controller)
    

    而在PaginationRecallComponent 中是:

    function initialize(&$controller)
    

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

    【讨论】:

    • @AdityaBhatt 您必须将Controller 添加到方法签名中。或者换个说法,第一个 sn-p 显示了第二个 sn-p 的样子。
    • 用最简单的话来说,你必须将函数initialize(&$controller)替换为public function initialize(Controller $controller)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-11
    • 1970-01-01
    相关资源
    最近更新 更多