• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get data based on the URL but using the same function

#1
[eluser]Dannymx[/eluser]
Well, basically what I am looking to do is something like this:

The user will be able to type an URL like:

Quote:example.com/list/schoolname1
and the user will see data from the School 1

or

Quote:example.com/list/schoolname2
and here the user get data from school 2

etc.

So I have a function called index

Code:
function index(){
//loads data from a database and then displays it in view
}

The function will be used with any school that is typed since the functionality is the same.

I used routing to remove the index from the URL '(/list/(:any)', but what I want to know is how to make the function to identify what school was typed in the URL and then get the data based on that segment, and also even if they type SchOoLNamE1 (case insensitive).

Thanks in advance.

#2
[eluser]osci[/eluser]
Code:
function index($school='') {
   //have values stored in uppercase or do search in db using UCASE
   // transform your segment to uppercase
   $school = strtoupper($school);
   //check database now

}

#3
[eluser]Dannymx[/eluser]
[quote author="osci" date="1305544408"]
Code:
function index($school='') {
   //have values stored in uppercase or do search in db using UCASE
   // transform your segment to uppercase
   $school = strtoupper($school);
   //check database now

}
[/quote]

I printed the $school value and I get "(:any)"

This is making conflict with the uri routing.

#4
[eluser]osci[/eluser]
post your route, it must be wrong if it's returning "(:any)"

#5
[eluser]Dannymx[/eluser]
[quote author="osci" date="1305545821"]post your route, it must be wrong if it's returning "(:any)"[/quote]

Code:
$route['list/(:any)'] = "list/index/(:any)";

#6
[eluser]osci[/eluser]
Code:
$route['list/(:any)'] = "list/index/$1";

#7
[eluser]Dannymx[/eluser]
[quote author="osci" date="1305545994"]
Code:
$route['list/(:any)'] = "list/index/$1";
[/quote]

Thank you, the parameter thing and that routing did the trick :-)


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.