CodeIgniter Forums
Argument is function problem! - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Argument is function problem! (/showthread.php?tid=21141)



Argument is function problem! - El Forum - 07-31-2009

[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!


Argument is function problem! - El Forum - 07-31-2009

[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


Argument is function problem! - El Forum - 07-31-2009

[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";


Argument is function problem! - El Forum - 08-01-2009

[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).