Perad Posted October 5, 2009 Share Posted October 5, 2009 Hey, I have created an 'awesome' - as in it works! - routing library. However it is somewhat limited and I don't have the knowledge to take it to the next level. It works something like this. Please note this isn't the actual code. $segments = explode('/', $url); // Trim and reorganise array if (count($segments) == 0) { // Use default route } if (count($segments) == 1) { // Load module/segment0.php - start class segment0 - load the index function or return 404 if this does not exist } if (count($segments) == 2) { // Same as above with the exception that segment1 is the function instead of index } This is where I am. I have tested it a lot. Either returns correct function/class or a 404 error. What I want to do is allow for more than 2 segments. I would like segments 3+ to become function parameters. How do I do this? Link to comment https://forums.phpfreaks.com/topic/176560-help-with-routing-script/ Share on other sites More sharing options...
MasterACE14 Posted October 5, 2009 Share Posted October 5, 2009 I don't entirely understand what you're asking. But you can optimize the script a little by doing this... $segments = explode('/', $url); // Trim and reorganise array $count = count($segments); if ($count == 0) { // Use default route } if ($count == 1) { // Load module/segment0.php - start class segment0 - load the index function or return 404 if this does not exist } if ($count == 2) { // Same as above with the exception that segment1 is the function instead of index } Link to comment https://forums.phpfreaks.com/topic/176560-help-with-routing-script/#findComment-930773 Share on other sites More sharing options...
cags Posted October 5, 2009 Share Posted October 5, 2009 When it comes to optimizing, since $count can only ever have one value you might aswell... $count = count($segments); if ($count == 0) { // Use default route } elseif ($count == 1) { // Load module/segment0.php - start class segment0 - load the index function or return 404 if this does not exist } elseif ($count == 2) { // Same as above with the exception that segment1 is the function instead of index } But it's not answering the original question and like MasterACE14 I don't have a clue what your asking. Link to comment https://forums.phpfreaks.com/topic/176560-help-with-routing-script/#findComment-930845 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.