1

我正在使用 Cakephp 2.3.0,加载以下组件。

class BreadCrumbsComponent extends Component {

public $components = array();
public $controller = null;

public function initialize($controller) {

}

public function startup($controller) {
    $this->controller = $controller;
}

public function beforeRender($controller) {

}

public function shutDown($controller) {

}

public function beforeRedirect($controller, $url, $status = null, $exit = true) {

}

public function handle($controllerName = NULL, $actionName = NULL) {
    pr($this->controller->modelClass);
}

}

错误后出现错误

Trying to get property of non-object [APP\Controller\Component\BreadCrumbsComponent.php, line 38]

我无法访问 $this->controller 那里。任何原因?我如何使它工作?

4

1 回答 1

4

阅读此处 启动方法在控制器之后调用,因此需要在初始化方法中初始化控制器,如下所示,

public function initialize(&$controller, $settings = array()) {
    $this->controller = $controller;
}
于 2013-05-20T09:02:56.470 回答