markyoung1984 Posted December 2, 2008 Share Posted December 2, 2008 In an MVC environment, what should a controller be like? Should it be a long series of switch statements? Should it be an object or some description? I just don't know and its confusing me. Quote Link to comment https://forums.phpfreaks.com/topic/135176-controllers-in-mvc/ Share on other sites More sharing options...
trq Posted December 2, 2008 Share Posted December 2, 2008 A basic front controller could simply be a series of conditions within a switch. A more robust front controllershould attempt to resolv urls to objects / methods. Quote Link to comment https://forums.phpfreaks.com/topic/135176-controllers-in-mvc/#findComment-704016 Share on other sites More sharing options...
markyoung1984 Posted December 3, 2008 Author Share Posted December 3, 2008 I do use objects in my code. I am relating GET variables to objects but within a switch statement. Is that how you would do it? Quote Link to comment https://forums.phpfreaks.com/topic/135176-controllers-in-mvc/#findComment-704768 Share on other sites More sharing options...
trq Posted December 3, 2008 Share Posted December 3, 2008 I do use objects in my code. I am relating GET variables to objects but within a switch statement. Is that how you would do it? No. A switch statement would meen its hard coded. Everytime you add a new action controller you would need to update the switch. A simple example of doing it dynamically (Not tested, just a demo). <?php $controller = $_GET['c']; $action = $GET['a']; if (file_exists("controllers/$controller.class.php")) { include "controllers/$controller.class.php"; $obj = new $controller; if (is_callable(array($obj, $action))) { $obj->$action(); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/135176-controllers-in-mvc/#findComment-704993 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.