[eluser]Muser[/eluser]
Hi CI comunity!
I'm trying to make an easy way to do static pages inside a page layout. By myself, I mean a static page is a page without dynamic php needed...
So, I tryed this...
In application/config/routes.php:
Code:
$route['default_controller'] = "home";
$route['scaffolding_trigger'] = "";
$route['noticia/(\d+)/(.*)'] = "noticies/view/$1";
$route['sindicacio-rss'] = "noticies/rss";
$route['guia-comercial/(\d+)'] = $route['guia/(\d+)'] = "guiacomercial/$1";
$route['qui-som'] = $route['quisom'] = "home/quisom";
$route['farmacies-de-guardia'] = $route['farmacies'] = "farmaciesguardia";
// When it isn't any of above...
$route['(.*)'] = "home/staticpage/$1";
In application/controllers/home.php:
Code:
//$page contains the uri submited
// example: www.example.com/agenda
// page parameter becomes: agenda
function staticpage($page)
{
//Search inside /views/static/ a .tpl with the name $page.tpl
if(file_exists(APPPATH.DIRECTORY_SEPARATOR.'views'.DIRECTORY_SEPARATOR.'static'.DIRECTORY_SEPARATOR.$page.'.tpl'))
{
//If exists, load the file inside the layout and output it to screen.
$this->smartylayout->view('static/'.$page.'.tpl');
}
else
{
//if not exists, show 404 error
show_404();
}
}
And the code works excellent... but with this strategy I need to define inside routes.php each controller I have...
Also, I don't know if the script plan becomes too memory and processor greedy...
Any suggestion?