且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Cakephp Helpers in Views和$ this

更新时间:2023-12-05 20:23:22

有碰撞会消灭你的帮助者的访问。假设我有一个名为 Form 的模型,并且在获得许多记录后决定在我的视图中执行这样的操作。

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/>';
}

看到发生了什么?我不小心只是重写了 $ form 变量,基本上丢失了我的 FormHelper

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

标准现在通过视图中的 $ this 访问所有帮助者。

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