問題描述
我第一次嘗試 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 版本,我得到了錯誤的版本還是再次發(fā)生了變化.好像找不到html helper.
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.
按要求提供更多信息:
這里是 index.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, line 13] Fatal error: Call to a member function link() on an non-object in/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.
發(fā)瘋5小時后更新
謝謝伙計們,它已排序,以防萬一有人遇到這個問題,主站點上的教程是舊的,沒有人努力更新它!!...在 index.ctp 示例中替換
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的manual上看,$html
應該是$this->Html
在 CakePHP 2.0 中.
From the manual of cakephp, it seems that $html
should be $this->Html
in CakePHP 2.0.
這篇關于在 CakePHP 2.0 中使用 Html Helper 時未定義的變量的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!