Dvd*_*d74 1 components cakephp initialization
我试图插入PaginationRecallComponent(http://bakery.cakephp.org/articles/Zaphod/2012/03/27/paginationrecall_for_cakephp_2_x),
App - > Controller - > Component - > PaginationRecallComponent.php
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
Run Code Online (Sandbox Code Playgroud)
CakePHP 2.4.2
您收到此错误是因为类中initialize方法的签名与PaginationRecallComponent其父类中的签名不同.
如果您查看代码,您将在Cake/Controller/Component.php签名中看到:
public function initialize(Controller $controller)
Run Code Online (Sandbox Code Playgroud)
而在PaginationRecallComponent它是:
function initialize(&$controller)
Run Code Online (Sandbox Code Playgroud)
在第一种情况下,$controller参数必须是实例Controller,而在第二种情况下,没有这样的约束.要摆脱错误,您只需将此约束添加到initialize方法的签名中即可PaginationRecallComponent.