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? Quote Link to comment 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 } Quote Link to comment 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. Quote Link to comment 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.