Can't get routes to work how I want it to |
[eluser]ElliotReevey[/eluser]
I started work on my first every project using Codeigniter and hoping you guys can help me out. I have a controller called campaign which has an index() and newcampaign() function which all works fine using the following urls http://website.com/campaign and http://website.com/campaign/newcampaign. However I am looking to extend this so that anything after http://website.com/campaign which is NOT equal to newcampaign routes to the viewcampaign() function for example http://website.com/campaign/campaign1. I have so far been working on the routes.php file in the config folder and have tried: Code: $route['campaign/^((?!newcampaign)\S*)'] = "campaign/$1"; However when I go to say http://website.com/campaign/campaign1 I get a 404 not found. Can anyone shed any light on how to achieve what im looking for? Cheers
[eluser]Bart Mebane[/eluser]
This is one way to do it: Code: route['campaign/new'] = 'campaign/newcampaign';
[eluser]ElliotReevey[/eluser]
Code: $route['campaign/newcampaign'] = 'campaign/newcampaign'; The above works, however I was hoping to achieve this by using a regular expression which says if NOT equal to newcampaign therefore I wouldn't have to add a new line for every other view that I created from the campaign controller.
[eluser]Bart Mebane[/eluser]
Hmmm ... not sure I'm understanding. If you route all non-newcampaign requests to the same place, wouldn't you still have problems if you later added additional functions? One alternative is to include viewcampaign explicitly in the url (http://website.com/campaign/viewcampaign/campaign1).
[eluser]ElliotReevey[/eluser]
Your right you would, but in the regular expression you could have "(newcampaign|deletecampaign)" or something to that degree rather than having to add new rules for each new page you want to exclude. I am aware you could add viewcampaign to the URL but thats what I am trying to avoid.
[eluser]Bart Mebane[/eluser]
My preference would be to have a separate route[] line for each function, because it makes things clearer to me, but I understand what you're saying. I've never used regexes in routes, so I'll defer to some of the other forum members. |
Welcome Guest, Not a member yet? Register Sign In |