我在第一次尝试 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
。
关于php - 在 CakePHP 2.0 中使用 Html Helper 时 undefined variable ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7162405/