cakephp博客教程中缺少Helper错误

时间:2012-11-26 10:49:41

标签: php cakephp cakephp-2.2

我刚刚开始使用php和cakePhp。尝试实现博客教程时遇到以下错误。
我按照教程中的步骤进行操作,直到http://book.cakephp.org/2.0/en/getting-started.html#creating-post-views

错误消息的屏幕截图在这里 -
[1]:http://i.imgur.com/xLvz3.png“top”
[2]:http://i.imgur.com/cJHPK.png“底部”

型号/ post.php中

    <?php        
   class Post extends AppModel {}

控制器/ PostsController.php

    <?php
class PostsController extends AppController {
public $helpers = array(’Html’, ’Form’);

public function index() {
    $this->set(’posts’, $this->Post->find(’all’));
}

public function view($id = null) {
    $this->Post->id = $id;
    $this->set(’post’, $this->Post->read());
}}

帖子/ index.ctp

     <h1>Blog posts</h1>
     <table>
<tr>
    <th>Id</th>
    <th>Title</th>
    <th>Created</th>
</tr>

<!-- Here is where we loop through our $posts array, printing out post info -->

<?php foreach ($posts as $post): ?>
<tr>
    <td><?php echo $post['Post']['id']; ?></td>
    <td>
        <?php echo $this->Html->link($post['Post']['title'],
     array('controller' => 'posts', 'action' => 'view', $post['Post']['id'])); ?>
    </td>
    <td><?php echo $post['Post']['created']; ?></td>
</tr>
<?php endforeach; ?>
<?php unset($post); ?>

1 个答案:

答案 0 :(得分:3)

用简单的引号“'”替换“'”。

因此您必须将助手声明为:

      public $helpers = array('Html', 'Form');

查找方法参数的相同更改:

      $this->set('posts', $this->Post->find('all'));

最后

      $this->set('post', $this->Post->read());