3

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(...
5
  • That's just a warning. Most likely you've got something like $var = $undefined_var + 1; and the warning is due to the $undefined_var. Commented Aug 23, 2011 at 14:16
  • 3
    Without showing some code, it's hard for somebody to help you. Please give some more details about what you are trying to do. Commented Aug 23, 2011 at 14:16
  • Sorry here is the code in the ctp file Commented Aug 24, 2011 at 1:25
  • I have added more info see the post above Commented Aug 24, 2011 at 1:35
  • You might be following an outdated tutorial that uses ver 1.2 conventions. If you're new to Cake I would recommend that you stick with the stable 1.3 release for now. It's well documented and you can later upgrade to 2.0 when it has matured enough. Commented Aug 24, 2011 at 8:02

3 Answers 3

9

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

Sign up to request clarification or add additional context in comments.

Comments

0

Just make this change:

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

Comments

0

From CakePHP 2.0 all Helpers are called on class (this) and with a first capital letter as standard $this->Html-> (Html). Same for Form Helper and such.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.