Check if controller exist |
[eluser]Roey[/eluser]
Hello everyone... I wander, Is there any way that i can check if controller exist and if not then go to another controller?
[eluser]LuckyFella73[/eluser]
As far as I know you can only check for classes (that's what controller are) that are loaded. What you can do is set up rules in config/routes.php that point to somewhere in case a controller is called that don't exist.
[eluser]Roey[/eluser]
ok... 1. where in the config file i can do this? 2. maybe if i tell you what i'm trying to do you can give another way to do it. I try to built a small cms with an option for the admin to create a new page. the page that he will create will be save in the view folder. what i think about is to build a controller which will display the page without creating a new controller. this is the controller: Code: <?php and i get the $page from the address bar. is there any other way to do so?
[eluser]LuckyFella73[/eluser]
I assume that $page is the name of the view_file that should be loaded? In that case you can check with the php function Code: file_exists() Have a look here: http://php.net/manual/de/function.file-exists.php Check if the view file can be found in your view directory and if not let the page display an existing one that makes sense for you.
[eluser]pickupman[/eluser]
Most common CMS will store page data in the database. Here is how I am doing this same thing Code: class Pages extends CI_Controller{ Now using these routes your links would be pages/home, pages/about_us, pages/services etc. |
Welcome Guest, Not a member yet? Register Sign In |