I have a problem with the current CodeIgniter. I have a CI installation with a "Pages" controller that loads static files from / views, but only up to 1 subfolder, and I want to add another subfolder to it.
To a large extent, this does the following:
- If the requested URL segment (e.g. site.com/url) is located in / views as a file (e.g. / views / url.php), it will load it from there, but if the URL segment (e.g. url) is actually in to the folder inside / views, it will load index.php from this folder (for example, / views / url / index.php while the URL is still on site.com/url).
- The above applies to any other file name, not just index.php. If I have site.com/url/buy, it will download the buy.php file from the / views / url folder.
I am trying to add a new subfolder to this structure:
- If I go to .com / url / buy / faq to download the faq.php file from / views / url / buy, etc.
The current Pages.php controller is as follows:
class Pages extends CI_Controller {
public function view($page = 'index', $sub_page = 'index') {
if ($page == 'index') {
$path = $page . '.php';
} else {
$path = $page . '/' . $sub_page . '.php';
}
if (!file_exists('application/views/pages/' . $path)) {
if (!file_exists('application/views/pages/' . $page . '.php')) {
show_404();
} else {
$path = $page . '.php';
}
}
$data['title'] = ucfirst($page);
$data['url'] = lcfirst($page);
$this->load->view('pages/modules/header', $data);
$this->load->view('pages/'. $path, $data);
$this->load->view('pages/modules/footer', $data);
}
}
Do you have any suggestions?
Thanks in advance!
source
share