CodeIgniter Forums
Get data based on the URL but using the same function - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Get data based on the URL but using the same function (/thread-41738.html)



Get data based on the URL but using the same function - El Forum - 05-15-2011

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


Get data based on the URL but using the same function - El Forum - 05-16-2011

[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

}



Get data based on the URL but using the same function - El Forum - 05-16-2011

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


Get data based on the URL but using the same function - El Forum - 05-16-2011

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


Get data based on the URL but using the same function - El Forum - 05-16-2011

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



Get data based on the URL but using the same function - El Forum - 05-16-2011

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



Get data based on the URL but using the same function - El Forum - 05-16-2011

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