Ricardo
Ricardo

Reputation: 1672

CodeIgniter "The page you requested was not found." error?

I'm having a problem with CodeIgniter. I've checked every possible solution on the internet and seems like nothing helps in my case. I'm not a big pro and it's my first time using CodeIgniter so don't be harsh with me.

routes.php:

$route['default_controller'] = "page";
$route['404_override'] = '';

$route['(:num)'] = "page/index/$1";

page.php:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Page extends CI_Controller {

    public function index($id=null) {

        $this->load->model('Image','',TRUE);
        $this->load->model('Banner','',TRUE);
        $image = $this->Image->getImageById($id);
        if (empty($image)) {
            show_404();
        }
        //db table `banner` always have three rows
        $banners=$this->Banner->getBanners();
        $data=array();
        $data['image']=$image;
        $data['banner']=$banners;
        $this->load->view('page_index', $data);
    }
}

Upvotes: 4

Views: 78675

Answers (7)

Amit Prajapati
Amit Prajapati

Reputation: 137

the controller will uppercase first letter if you are using Unix server

Upvotes: 1

isarojdahal
isarojdahal

Reputation: 1186

I have read your problem. You have done mistake while saving the controller.

It should be saved in capital i.e. Page.php but you have saved as page.php

I think this will work out !

Upvotes: 4

Ravinder Payal
Ravinder Payal

Reputation: 3031

If you have developed your application on Windows, you might have not set first character of Controllers and Models name as a capital character.

like /controllers/home.php to /controllers/Home.php

On Linux file names are case sensitive.

Note:- This is a solution to a possible problem. There may be issues of mis configuration, server and path variables.

Upvotes: 2

score
score

Reputation: 521

I am also quite new to codeigniter. This is what I would do at the beginning:

  1. autoload database and configure the database.php file
  2. autoload helper file 'url', 'file'
  3. configure your base url "://yourhost/yourworkingfolder" (if you are working on local host)
  4. You need to route your page. Go to route.php, and give the name of your default controller page name and if it seems working than you r good to further with additional task.

Please, correct me if I am wrong. I am a newbie to codeigniter. Thankx

Upvotes: 0

Ricardo
Ricardo

Reputation: 1672

Thank you everyone, The problem was that i stated in page.php that if there is no images in the database it'll show 404 page:

if (empty($image)) {
    show_404();
}

I've added two images to the DB and now it works.

Upvotes: 0

bdscorvette
bdscorvette

Reputation: 125

Did you construct the parent? Public function _construct() { Parent::_construct(); }

Upvotes: 2

semanticMike
semanticMike

Reputation: 36

This doesn't sound like a Codeigniter error. It could be your webserver configuration. Do you have a webserver and php server setup and configured on your machine? Have you configured an .htaccess file to replace "index.php"?

Upvotes: 1

Related Questions