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 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题