在CakePHP 2.0中使用Html Helper时未定义的变量 [英] Undefined var when using Html Helper in CakePHP 2.0

查看:212
本文介绍了在CakePHP 2.0中使用Html Helper时未定义的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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


未定义的变量:html [APP / View / Posts / index。 ctp,line 13]

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

我有版本2.0-alpha,我有错误的版本或什么改变了。看起来找不到html助手。

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.

更多信息请求:

这里是索引。 ctp档案

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

数据肯定会通过,但我得到的错误是第13行:

The data is definitely coming through but the error I get is this on line 13:


未定义的变量:html [APP / View / Posts / index.ctp,第13行]致命错误:调用成员函数link - 在/ home中显示对象

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.

更新5小时后会疯狂

感谢各位排序,任何人都有这个问题在主网站的教程是一个老,没有人做了努力更新它!! ... in the index.ctp example

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(... 

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


推荐答案

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

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

这篇关于在CakePHP 2.0中使用Html Helper时未定义的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆