1

我刚开始使用 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 “bottom”

模型/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); ?>

4

1 回答 1

3

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

所以你必须将助手声明为:

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

find 方法参数的相同更改:

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

终于

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

阿纳斯

于 2012-11-26T12:17:38.430 回答