Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined var when using Html Helper in CakePHP 2.0

I am getting this error on my first attempt of CakePHP:

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

I have version 2.0-alpha, have I got the wrong version or what has changed again. Seems it can't find the html helper.

More info as requested:

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 is definitely coming through but the error I get is this on line 13:

Undefined variable: html [APP/View/Posts/index.ctp, line 13] Fatal error: Call to a member function link() on a non-object in /home

I'm quite new I hope this helps.

Update 5hrs later of going crazy

Thanks guys it's sorted incase anybody has this problem the tutorial on the main site is an old one and nobody has made the effort to update it!! ...in the index.ctp example replace

$html->link(... 

with

$this->Html->link(...
like image 337
Ola Avatar asked Apr 27 '26 11:04

Ola


1 Answers

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

like image 109
xdazz Avatar answered Apr 29 '26 06:04

xdazz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!