Argument is function problem! |
[eluser]Unknown[/eluser]
Hey! Not sure why.. I think it's because CodeIgniter is said to be VERY fast compared to other frameworks.. so I'm currently working with this setting up my new site... I really like coding the site myself, because I have more control. But this kind of framework makes the code cleaner and progress faster... Anyway, to my issue. I know this: http://localhost/index.php/CONTROL/FUNCTION/... but I created a .htaccess file which makes this: http://localhost/CONTROL/FUNCTION/... Now, here is my problem. The control is named "users.php", and currently has index function implemented... It's all fine and dandy, but how can I make this possible: http://localhost/users/MrDoe http://localhost/users/JamesBond http://localhost/users/Jezus Obviously, I don't and don't want to have functions named MrDoe, JamesBond etc. The idea is that I get those to the class as arguments. I tried "function index($user) {}" but that didn't seem work. I think this looks wierd: http://localhost/users/user/MrDoe Suggestions? Edit: My bad. I guess this post should have been in "Code and Application Development"? I don't want to double post and I can't move it nor delete it... Thanks!
[eluser]designfellow[/eluser]
[quote author="Chillance" date="1249116706"]Hey! Now, here is my problem. The control is named "users.php", and currently has index function implemented... It's all fine and dandy, but how can I make this possible: http://localhost/users/MrDoe http://localhost/users/JamesBond http://localhost/users/Jezus Obviously, I don't and don't want to have functions named MrDoe, JamesBond etc. The idea is that I get those to the class as arguments. I tried "function index($user) {}" but that didn't seem work. I think this looks wierd: http://localhost/users/user/MrDoe Suggestions? Thanks![/quote] Hi, Just open your routes.php file in the application/config folder and add a new line like this $route['users/:any'] = "users/user/$1"; Hope, it will work for you. Happy Coding, DesignFellow
[eluser]Unknown[/eluser]
[quote author="designfellow" date="1249117739"][quote author="Chillance" date="1249116706"]Hey! Now, here is my problem. The control is named "users.php", and currently has index function implemented... It's all fine and dandy, but how can I make this possible: http://localhost/users/MrDoe http://localhost/users/JamesBond http://localhost/users/Jezus Obviously, I don't and don't want to have functions named MrDoe, JamesBond etc. The idea is that I get those to the class as arguments. I tried "function index($user) {}" but that didn't seem work. I think this looks wierd: http://localhost/users/user/MrDoe Suggestions? Thanks![/quote] Hi, Just open your routes.php file in the application/config folder and add a new line like this $route['users/:any'] = "users/user/$1"; Hope, it will work for you. Happy Coding, DesignFellow[/quote] Ah, of course! You missed the parentheses though.. Thanks! $route['users/(:any)'] = "users/user/$1";
[eluser]jedd[/eluser]
[quote author="Chillance" date="1249116706"] I think this looks wierd: http://localhost/users/user/MrDoe [/quote] Rather than routing around this (and future instances where you have a method the same name as your controller class) you may want to re-think what the method actually does, and give it a more relevant name. I think a few people follow the class-is-noun, method-is-verb approach to design (and consequent clarity of naming is a freeby bonus). |
Welcome Guest, Not a member yet? Register Sign In |