douqiang3768 2017-04-04 08:10
浏览 23
已采纳

Cakephp博客教程 - 添加图层

I installed cakephp 2.9.7 and i am doing blog tutorial by referring(https://book.cakephp.org/2.0/en/tutorials-and-examples/blog/part-two.html).

Create a Post model

class Post extends AppModel {
}

Creating a Post controller

class PostsController extends AppController {
    public $helpers = array('Html', 'Form');

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

Creating Post Views.I created Posts folder inside app/View folder.And i updated Database.php too so that it can connect to mysql database.

<!-- File: /app/View/Posts/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); ?>
</table>

But when i run in my local cakephp/app error says Error: The view for AppController::index() was not found.Confirm you have created the file: App/index.ctp in one of the following paths: cakephp/app/View/App/index.ctp.stuck with solving this as i am new to cakephp.

  • 写回答

1条回答 默认 最新

  • duandang2838 2017-04-04 08:46
    关注

    Seems like you are requesting the wrong URL. If you request http://your-domain.de/app Cake will try to find the Action and View for index of the AppController.

    You should get your desired Controller and View by requesting http://your-domain.de/posts or http://your-domain.de/posts/index.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记