【问题标题】:Missing Helper error in cakephp blog tutorialcakephp 博客教程中缺少 Helper 错误
【发布时间】:2012-11-26 10:49:40
【问题描述】:

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

错误消息的屏幕截图在这里-
[1]:http://i.imgur.com/xLvz3.png“顶”
[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); ?>

【问题讨论】:

  • @Ross 从文件中添加了代码。
  • 检查我对第一个问题的回答。其次,它必须通过我在答案中发布的更改来解决

标签: php cakephp cakephp-2.2


【解决方案1】:

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

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

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

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

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

终于

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

阿纳斯

【讨论】:

  • 谢谢@Anas。不敢相信它是如此简单。我之前使用的是 pdf 版本的食谱,我认为这就是复制代码时不同引号的来源。
  • @user603125 学习时不要复制/粘贴代码!最好自己写下来,因为: 1. 你会仔细思考你输入的内容 2. 你会对代码有更深入的理解 3. 你会在打字时获得肌肉记忆 一般来说,在学习时复制/粘贴代码是一个非常糟糕的做法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-10
相关资源
最近更新 更多