Reputation: 1211
I have the following files:
routes.php
$route['default_controller'] = "first";
$route['404_override'] = '';
$route['page/(:any)'] = 'page/view/$1';
page.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Page extends CI_Controller {
public function index() {
$this->load->view('first');
}
public function view($page = 'first') {
if ( ! file_exists('application/views/pages/'.$page.'.php'))
// Whoops, we don't have a page for that!
show_404()
}
$this->load->view('pages/'.$page);
}
}
?>
impressum.php (in views/pages/impressum.php)
<p>Hello</p>
Now when I load http://xxxx.de/page/impressum it shows me just a blank page. When I load www.xxxx.de it shows me the "first" page / default page.
It doesn't even load the "first" page when I try to load: www.xxx.de/page/
Just don't know where I have the error/mistake.
My folder structure is:
http://d.pr/i/vYgw
An help is really appreciated. Thanks.
Upvotes: 0
Views: 1299
Reputation: 4574
you need to check $page in view method of Page Controller as you are passing any in your route.php file
$route['page/(:any)'] = 'page/view/$1';
www.xxx.de/page/ will pass an empty string or variable to view method you can check it like
if(!strlen($page)){
$page = "first";
}
better way to use uri class to get page
public function view() {
$page = $this->uri->segment(2, 'first');
if ( ! file_exists('application/views/pages/'.$page.'.php')){
// Whoops, we don't have a page for that!
show_404()
}
$this->load->view('pages/'.$page);
}
if no segment found it will pass first as default
Upvotes: 1