CodeIgniter Forums

Full Version: Add a parameter to the URL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Unknown[/eluser]
Hello everybody,

It was difficult to write a title about my problem but i'm going to explain you here.

I would like to developp a website that will offer to create their own spaces with blog, forum, file management...

There would be the main website that I will call as example http://www.spacecreation.com/. There would be at this URL the main platform with a portal, forum for everybody. To be on the common forum, I would like that the URL be http://www.spacecreation.com/forum/viewthread/874

Blue = domain name
Green = sub-folder of "application"
Orange = controler
Yellow = parameter

All of that was for the common platform but how could I do assign in the URL the name of space created by an user like :

http://www.spacecreation.com/userspace1/forum/viewthread/874

Purple = space of the user.

How to change in the URL the name of the spaces to redirect to the specified. It could be considered as a parameter but not a the end of the url.

How to do that with code igniter or with only php.

I hope that you will understand my question and that you will help me to find a solution.

El Forum

[eluser]Alias M2K[/eluser]
Man, you should go through the CodeIgniter URL's section in the CodeIgniter Documentation If you already had, and is still clueless, here is a small hint:

If http://example.com is a CodeIgniter powered app, with the default controller set to your controller, then it would hit your controllers index function.

Now, if you call another function, say f1, then the url would change to http://example.com/index.php/controller/f1. (Ok, don't get messed up by the long URL's :roll: you can use the site_url function in the URL Helper).

The above example URL will work only if you are making function calls with no parameters. If you want to make function calls with one or more parameters, then your URL's should look like these:
For 1 parameter: http://example.com/index.php/controller/f1/p1
For 2 parameters: http://example.com/index.php/controller/f1/p1/p2 etc.

For your forum idea, I think the best way would be to implement a function(view_topic), which accepts parameters like forum_id, thread_id, user_id etc and then workout your magic!

All the best dude Smile

El Forum

[eluser]Unknown[/eluser]
I know that but I don't want http://www.example.com/class/function/parameter.

I want a way to do http://www.example.com/parameter1/class/...parameter2

Parameter1 would be the name of the user space. That wouldn't be a function parameter but a simple parameter.

El Forum

[eluser]HomersBrain[/eluser]
How about using subdomains so instead of

http://www.spacecreation.com/userspace1/forum/viewthread/874

you have

http://userspace1.spacecreation.com/forum/viewthread/874

See here for more info

http://ellislab.com/forums/viewthread/184700/

El Forum

[eluser]dfreerksen[/eluser]
Check out the URI Routing documentation

Inside your routes.php file you would have to do something like this
$route['(:any)/forum/viewthread/(:num)] = "forum/viewthread/$1/$2";

Now your viewthread method will accept two parameters. The first one is the username and the second on is the thread id.

El Forum

[eluser]Alias M2K[/eluser]
Routing is a good idea :-)