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);
}
}
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"?
I am also quite new to codeigniter. This is what I would do at the beginning:
Please, correct me if I am wrong. I am a newbie to codeigniter. Thankx
Did you construct the parent? Public function _construct() { Parent::_construct(); }
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.
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.
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 !
the controller will uppercase first letter if you are using Unix server