问题
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);
}
}
回答1:
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 !
回答2:
Did you construct the parent? Public function _construct() { Parent::_construct(); }
回答3:
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.
回答4:
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"?
回答5:
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.
回答6:
I am also quite new to codeigniter. This is what I would do at the beginning:
- autoload database and configure the database.php file
- autoload helper file 'url', 'file'
- configure your base url "://yourhost/yourworkingfolder" (if you are working on local host)
- 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
回答7:
the controller will uppercase first letter if you are using Unix server
来源:https://stackoverflow.com/questions/17633582/codeigniter-the-page-you-requested-was-not-found-error