4

我们都知道它$this->element()已被弃用。他们说,The "$options['plugin']" is deprecated and will be removed in CakePHP 3.0. Use "Plugin.element_name" instead.。那么,当我从视图而不是插件中使用它时,将会有什么替代品呢?或者$this->element()不推荐使用从视图。

我应该从视图中使用该功能吗?

4

2 回答 2

5

element()方法本身不被弃用,仅使用数组中的plugin键。$options这意味着您应该使用

$this->element('Contacts.helpbox');

代替

$this->element('helpbox', array(), array('plugin' => 'Contacts'));

另请参阅http://book.cakephp.org/2.0/en/views.html#requesting-elements-from-a-plugin

于 2013-09-19T15:31:11.970 回答
1

就像上面所说的 dhofstet 一样,仅不推荐使用pluginkey in 。$options

要在插件中渲染元素,您可以使用它

$this->element('Contacts.helpbox');

(或者)

您还可以通过设置渲染元素 $this->plugin = pluginname,然后$this->element('element_name)'

IE

$this->plugin = 'Contacts';
$this->element('helpbox');

这将呈现插件中的helpbox元素Contacts

于 2013-09-20T04:52:43.447 回答