找不到PostsController :: index() - CakePHP

Gen*_*oax 6 php apache cakephp wamp autoload

我想把手放在cakephp上.所以我开始使用cakephp演示博客应用程序.我按照本教程的前几个步骤进行操作,当我尝试加载帖子控制器时,它说

Missing View
Error: The view for PostsController::index() was not found.

Error: Confirm you have created the file: T:\Project Folders\NetBeans\cakeBlog\app\View\Posts\index.ctp
Run Code Online (Sandbox Code Playgroud)

我在stackoverflow,cakephp论坛甚至googlegroups中都搜索了很多这方面的内容,但是没有一个解决方案似乎对我有用.发布的大部分解决方案如下:

  1. 检查mod_rewrite是否已启用 - 是的我启用了它.

  2. 检查是否将index.ctp命名为index.ctp而不是index.cpt,Index.ctp或任何其他变体. - 是的我已将索引放置如下app/views/Posts/index.ctp(使用netbeans向导)

  3. 使用标签而不是php短标签 - 我使用传统的标签

发展环境

Web服务器 - WAMP我创建了一个名为cakeblog并指向它的别名cakephp_folder/app/webroot/

cakeblog.conf

Alias /cakeblog/ "T:\Project Folders\NetBeans\cakeBlog\app\webroot/" 

<Directory "T:\Project Folders\NetBeans\cakeBlog\app\webroot/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
        Order allow,deny
    Allow from all
</Directory>
Run Code Online (Sandbox Code Playgroud)

应用程序/根目录/ htaccess的

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /cakeblog
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

我还加载了本地化和debugkit插件.我只是将已放置的文件夹放入app/plugin并在bootstrap.php中添加以下内容

bootstrap.php中

CakePlugin::load('DebugKit'); //Loads a single plugin named DebugKit
CakePlugin::load('Localized');
Run Code Online (Sandbox Code Playgroud)

core.php中

Configure::write('debug', 1);
Run Code Online (Sandbox Code Playgroud)

我能够启动应用程序,我看到欢迎页面很好.我在startup.png中附上了它的快照

启动

现在,让我粘贴代码,我只需从教程中复制粘贴:

应用程序/模型/ post.php中

   <?php
    class Post extends AppModel {
        //put your code here
    }
    ?>
Run Code Online (Sandbox Code Playgroud)

应用程序/控制器/ PostsController.php

<?php

  class PostsController extends AppController {
    //put your code here
    public $helpers = array('Html', 'Form');

     public function index() {
        $this->set('posts', $this->Post->find('all'));
    }
     public function view($id = null) {
        if (!$id) {
            throw new NotFoundException(__('Invalid post'));
        }

        $post = $this->Post->findById($id);
        if (!$post) {
            throw new NotFoundException(__('Invalid post'));
        }
        $this->set('post', $post);
    }
}

?>
Run Code Online (Sandbox Code Playgroud)

应用程序/视图/页/帖子/ index.ctp

<!-- 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>
Run Code Online (Sandbox Code Playgroud)

请检查附件output.png以获取我收到的输出的快照http://localhost/cakeblog/posts:

产量

kic*_*caj 3

将目录 app/View/Pages/Posts/ 更改为 app/View/Posts/

每个控制器都有自己的目录和视图文件。