Undefined var when using Html Helper in CakePHP 2.0

I get this error the first time I try CakePHP:

Undefined variable: html [APP / View / Posts / index.ctp, line 13]

I have version 2.0-alpha, I have the wrong version or what has changed again. It seems he cannot find the html helper.

Additional information on request:

Here is the index.ctp file

<?php foreach ($posts as $post): ?> <?php echo $post['Post']['id']; ?> <?php ##line 13 here echo $html->link($post['Post']['title'], array('controller' => 'posts', 'action' => 'view', $post['Post']['id'])); ?> <?php echo $post['Post']['created']; ?> <?php endforeach; ?> 

The data certainly passes, but the error I get is on line 13:

Undefined variable: html [APP / View / Posts / index.ctp, line 13] Fatal error: call of member function-function () for non-object in / home

I am brand new, hope this helps.

Update 5 hours after craziness

Thank you guys, he figured out that someone has this problem, the textbook on the main site is old, and no one made an effort to update it! ... in the index.ctp example, replace

 $html->link(... 

from

 $this->Html->link(... 
+3
source share
3 answers

From the cakephp tutorial, it seems that $html should be $this->Html in CakePHP 2.0.

+9
source

Just make this change:

 <?php ##line 13 here echo $this->html->link($post['Post']['title'], array('controller' => 'posts', 'action' => 'view', $post['Post']['id'])); ?> 
0
source

From CakePHP 2.0, all helpers are called in the ( this ) class and have the first capital letter as the standard $this->Html-> ( Html ). The same goes for Form Helper, etc.

0
source

Source: https://habr.com/ru/post/912456/


All Articles