I am having a problem with Cake PHP blog tutorial for beginners. I got an error stating I need to create a PostsController.php file, when trying to open the site.com/posts/index page, but I already have the PostsController.php in place.
I am using cake PHP ver 2.3.8
This is the error I get
Error: PostsController could not be found.
Error: Create the class PostsController below in file: app\Controller\PostsController.php
I've followed the tutorial to the letter, and put the files correctly in the directory.
Here is the PostsController.php file I created.
<?
class PostsController extends AppController {
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);
}
}
?>
Here is the Post.php file (the model)
<?
class Post extends AppModel {
}
?>
and here is the index.ctp file
<!-- 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>
I've already googled around for the solution and found out that a lot of people is having the same problem, but It's either their solution is not working for my case or they fixed it by themself and didn't post the solution.
Please help me...
UPDATE
the issue has been resolved, it was the <?php
tag that was missing.