繁体   English   中英

cakephp博客教程中缺少Helper错误

[英]Missing Helper error in cakephp blog tutorial

我刚刚开始使用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); ?>

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

所以你必须声明帮助者:

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

find方法参数的相同更改:

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

最后

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

阿纳斯

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM