开发者

What is the difference between "$form->..." and "$this->Form->..." in CakePHP?

开发者 https://www.devze.com 2023-04-06 03:07 出处:网络
This seems simple and I think I know the answer but I\'ve searched and can\'t find anything to back up my assumption.

This seems simple and I think I know the answer but I've searched and can't find anything to back up my assumption.

Many CakePHP code samples use the following syntax:

开发者_StackOverflow中文版echo $form->inputs();

When I write Cake views using 1.3 or 2.0-RC1, the above syntax does not work but the following does:

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

Is $form simply a deprecated syntax from an old version? Or is it a community-accepted shorthand for abbreviating the longer $this->Form version? (Or something else?)


I noticed that myself before. By taking a look into the CakePHP-books for versions 1.2 and 1.3 it turns out, that they use $form up to version 1.2 and $this->Form since version 1.3. So $form seems to be deprecated now.

Version 1.2: http://book.cakephp.org/view/183/Creating-Forms
Version 1.3: http://book.cakephp.org/view/1384/Creating-Forms

EDIT:
For further explanation see: Cakephp Helpers in Views and $this


$form is deprecated syntax for 1.3. It's used in cakephp 1.2

If you are using cakephp version 1.2, you'll need $form. Otherwise, when you are using cakephp 1.3 you'll need $this->Form

0

精彩评论

暂无评论...
验证码 换一张
取 消