PostsController :: index () not found - CakePHP

I'm trying to get a trick. So I started working with the cakephp demo blog. I followed the first few steps of the tutorial, and when I try to load the message controller, it says

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 

I searched a lot about this both in stackoverflow, cakephp forum and even googlegroups, but none of the solutions seem to work from me. Most published solutions:

  • Check if mod_rewrite is on - Yes, it is on.

  • Make sure you specify index.ctp as index.ctp and not index.cpt, Index.ctp or any other option. - Yes, I placed the index as follows: app / views / Posts / index.ctp (using the netbeans wizard)

  • Use tags instead of short php tags. I use a regular tag

Development environment

Web Server - WAMP I created an alias named cakeblog and pointed it to 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> 

application /Webroot/.htaccess

 <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /cakeblog RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule> 

I also downloaded the localization and the debugkit plugin. I just placed the subfolders in the application / plugin and added the following to bootstrap.php

bootstrap.php

 CakePlugin::load('DebugKit'); //Loads a single plugin named DebugKit CakePlugin::load('Localized'); 

core.php

 Configure::write('debug', 1); 

I can run the application and I see the welcome page fine and fine. I attached a snapshot to it in startup.png

startup

Now let me paste the code that I just copied from the tutorial:

application / model / post.php

  <?php class Post extends AppModel { //put your code here } ?> 

application / controller / 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); } } ?> 

app / view / Pages / Posts / 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> 

Please check the attachment output.png for a snapshot of the output I get for http://localhost/cakeblog/posts :

output

+6
source share
2 answers

Change directories app / View / Pages / Posts / to app / View / Posts /

Each controller has its own directory with view files.

+3
source

The file view is stored in / app / View /, in a folder named after the controller that uses the files, and named after the action that corresponds. In your example, the view file for the "index ()" Post Controllers "action is usually located in / app / View / Posts / index.ctp.

0
source

All Articles