Welcome Guest, Not a member yet? Register   Sign In
Using controllers as inputs
#1

[eluser]Unknown[/eluser]
Hi,

I'm developing a project for my school wherein I want to pass the student name as a parameter instead of the controller.

Eg:
--------------------------
Student name: Richard
URL: http://domain.com/richard
--------------------------

Is this possible? How do I implement it since the 1st parameter is a controller?
#2

[eluser]Unknown[/eluser]
You should use config/routes.php.

Take a look on URI Routing in CI Manual.

Then check for:
Code:
$route['product/(:any)'] = "catalog/product_lookup";
#3

[eluser]obiron2[/eluser]
Not really answering your question, more asking why you want to do it in the first place

Why don't you want to use a controller name in the URL

e.g. www.domain.com/student/richard


Whatever you do you will still need to have a controller and parse the student name as a parameter

Your site will simply be a list of pages for students as you will not be able to identify the difference between , say, a student and an event

What would you want the URL to look like for

www.domain/index.php/events/prom-night

you could also try using 301 redirects in the .htaccess file but I think you will still struggle to distinguish between student profiles and other parts of the website




#4

[eluser]TheFuzzy0ne[/eluser]
Routing is the way to do that, but bare in mind that it will be difficult if you ever decide to implement any controller. For example, let's assume you want a "contact" page. Normally, you'd go to www.yourdomain.com/contact. With your system this won't work unless you make an allowance for it. It will assume that "contact" is a name. This is why it makes more sense to pass it as a parameter to a controller that you specify in the URL, for example, www.yourdomain.com/profile/richard, so you have at least some separation of functionality.




Theme © iAndrew 2016 - Forum software by © MyBB