Cakephp Helpers in Views and $this

天涯浪子 提交于 2019-12-10 17:47:46

问题


I'm trying to determine what the best standard is for using helpers in views whether is should be

echo $form->input();

or

echo $this->Form->input();

In the CakePHP manual ver 1.2 the Helper class is accessed by the helper object directly, whereas in the 1.3 book the helper object is accessed through the View.

Does this matter?

Leo


回答1:


It really only matters because of the possibility of having a collision that will "wipe out" your access to the helper. Say I had a model named Form and decided to do something like this in my view after getting many records.

foreach ($forms as $form) {
    echo $form['Form']['name'] . '<br/>';
}

See what happened there? I accidentally just overwrote the $form variable, basically losing my FormHelper.

The standard is to now access all helpers via $this in the view.



来源:https://stackoverflow.com/questions/5106953/cakephp-helpers-in-views-and-this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!