Welcome Guest, Not a member yet? Register   Sign In
dynamic functions
#1

[eluser]Unknown[/eluser]
Hi there.. im new to code igniter.. started it about 3hours ago. and im in the middle of transforming my site to use CI framework. and im wondering how to go about this.

I have several users who are members of my site and part of the development team.
if you go to
about.php?u= {their username} it brings up a little bio
so how would i make it so that if they go to
about/{username}

i know i can go to about.php and make a function for each of their usernames and that will work, but i was hoping that there is another way to do it.

im sure this has been addressed before and its probably somewhere on the wiki or the forum but couldnt find it. Any help is greatly appreciated.
#2

[eluser]schnoodles[/eluser]
You could have something like

class About extend Controller {

function user( $username ) {
.. SQL to grab username info ..
.. view to pass the information to ..
}

}

Then you can access it by about/user/brandenw
#3

[eluser]Unknown[/eluser]
yes i started doing that.. but is there away to get rid of the user portion of it so that its just about/brandenw. i think that would have to be done in the routes.. but im still trying to figure out how that would work.
#4

[eluser]Huan[/eluser]
You could try: routes['about/:any'] = about/user/xxx
#5

[eluser]Michael Wales[/eluser]
Create a route for all of your named methods (the ones in which you know exist). The last route in your routes.php file should point towards the user-handling method().

Since routing works from top-to-bottom, all of your known controllers will be picked up by their respective routes and anything left over will be picked up by the user handler.

Example: The following will forward any requests for blog/(number) to the correct controller and anything else will be forwarded to the user controller (to display a profile or something).

Code:
$route['default_controller'] = "home";
$route['scaffolding_trigger'] = "";
$route['blog/(\d+)'] = "blog/view/$1";
$route['([a-z]+)'] = "user/view/$1";

Note: Don't quote my regex, I really suck at it.




Theme © iAndrew 2016 - Forum software by © MyBB