0
votes

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
your link should be cakephp/poststarikul05
Offtopic: You really shouldn't start any new projects with CakePHP 2.x anymore, 3.x is the way to go!ndm
I have written same as in that of blog tutorial.And the file also in the specified path as that in blog tutorial. index.ctp is in app/View/Posts/index.ctp only.But error says Confirm you have created the file: App/index.ctp in one of the following paths: cakephp/app/View/App/index.ctp.Manasa

1 Answers

1
votes

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.