-2

创建自己的组件的文档很糟糕。

如何读取组件内的模型数据?

尝试做一些简单的事情,例如尝试获取 $this->request->params['pass'][0] 让我想自杀。考虑到组件应该插入控制器,我很惊讶它是如此困难。

4

1 回答 1

1

你为什么不使用现有的信息?例如,您可以直接查看代码。它是开源的,易于通过 github 浏览:

https://github.com/cakephp/cakephp/blob/2.3/lib/Cake/Controller/Component/PaginatorComponent.php#L226

在那里,您会发现可以从任何 API 或文档中获得的更多信息。例如,使用

public function __construct(ComponentCollection $collection, $settings = array()) {
    $settings = array_merge($this->settings, (array)$settings);
    $this->Controller = $collection->getController();
    parent::__construct($collection, $settings);
}

进而

$this->Controller->... 

在代码中的任何地方,您都可以从当前控制器访问几乎任何内容。就像你在这个控制器里面一样。

同样:

$this->Controller->request->params['pass'][0]

要不就

$this->Controller->request->pass[0]

PS:除了所有这些测试用例之外,还有超过 6 个其他组件可供学习。

于 2012-09-21T21:40:43.640 回答