Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
737 views
in Technique[技术] by (71.8m points)

php - 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(...
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...