Nitish
Nitish

Reputation: 2763

Codeigniter shows 404 no page found.

Well I have a strange problem in my Codeigniter page. I have a controller class books.php

> <?php
> //echo 'Hello';
> class Books extends CI_Controller{
>     function __construct() {
>         parent::__construct();
>     }
>     
>     
>     function main()
>     {
>         $this->load->view('main_view');
>     }
>     
>     function input()
>     {
>         $this->load->view('input_view');
>     } } ?>

Now if I point my browser to http://localhost/CodeIgniter/index.php/books it shows 404 Page not found. Now If I add a echo 'Hello'; just above the class declaration, it shows hello and at the top of the page and after that line the same 404 error.Is this due to permission roblem. books.php have 777 permission.

Upvotes: 0

Views: 2828

Answers (5)

Petre Pătraşc
Petre Pătraşc

Reputation: 2313

When accessing:

http://www.example.com/CodeIgniter/index.php/books

the default router will actually load up

http://www.example.com/CodeIgniter/index.php/books/index

It is therefore looking for the index method.

Try adding the method or calling either of the method that you have defined:

http://localhost/CodeIgniter/index.php/books/main
http://localhost/CodeIgniter/index.php/books/input

Also, you should refrain from having 777 permissions on your files.

Upvotes: 2

Kalaiyarasan
Kalaiyarasan

Reputation: 13364

Please try with following code

<?php
> //echo 'Hello';
> class Books extends CI_Controller{
>     public function index() {
>         echo "check";
>     }
>     
>     
>     function main()
>     {
>         $this->load->view('main_view');
>     }
>     
>     function input()
>     {
>         $this->load->view('input_view');
>     } } ?>

Upvotes: 0

Stanley
Stanley

Reputation: 5127

You are missing the index() function. Refer to CodeIgniter URLs topic in their user guide to find out more about their segment-based approach.

Upvotes: 1

Varun Bajaj
Varun Bajaj

Reputation: 1043

Please create a index function inside your books.php or just for a sake of test just rename main function signature as follows -

function index()

{
    $this->load->view('main_view');
}

Upvotes: 0

danish hashmi
danish hashmi

Reputation: 484

> <?php
> //echo 'Hello';
> class Books extends CI_Controller{
>     function __construct() {
>         parent::__construct();
>     }
>     
>     
>     function index()
>     {
>         $this->load->view('main_view');
>     }
>     
>     function input()
>     {
>         $this->load->view('input_view');
>     } } ?>

Upvotes: 2

Related Questions