编程语言
首页 > 编程语言> > 在CakePHP 2.0中使用Html Helper时未定义的var

在CakePHP 2.0中使用Html Helper时未定义的var

作者:互联网

我第一次尝试CakePHP时收到此错误:

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

我有版本2.0-alpha,我有错误的版本或再次改变了什么.好像它找不到html助手.

更多信息请求:

这是index.ctp文件

<?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; ?> 

数据肯定是通过,但我得到的错误是在第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

我很新,我希望这会有所帮助.

更新5小时后变得疯狂

谢谢大家分类,如果有任何人有这个问题,主站点上的教程是旧的,没有人已经努力更新它! …在index.ctp示例中替换

$html->link(... 

$this->Html->link(...

解决方法:

从cakephp的手册中,似乎$html应该是CakePHP 2.0中的$this-> Html.

标签:cakephp-2-0,php,cakephp
来源: https://codeday.me/bug/20190723/1515286.html