Alphabetical Menu |
[eluser]kashi[/eluser]
Hi everyone. im new with CI and im having a problem: i want to create an alphabetical menu, you know, Code: a-b-c-d-e-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z and what i want (as you imagine) is that when you click on the "A" you get the results of all the objects starting with the letter A. in mysql is something like this Code: SELECT * but i dont know how to adapt it to CI. Hope you can help me! PS: sorry for my english, is not my native language.
[eluser]Ckirk[/eluser]
Check out the manual section on Active Records The part, which interests you here is "$this->db->like();" your code would look something like: Code: $this->db->like('name', 'A', 'after'); Hope that helps
[eluser]kashi[/eluser]
thanks for helping me! so i should make 26 pages one for each view? or there is a simpler way to do it?
[eluser]Pert[/eluser]
You can use controller attributes to pass in a letter, for example Code: class items extends CI_controller Now you can do something like this with your url Code: /items/listing
[eluser]kashi[/eluser]
And how i add the letters? Using href =item/listing/a Or there is something else i should know Again sorry for asking everything. Thanks !
[eluser]Pert[/eluser]
One option, in your view file Code: $this->load->helper('url');
[eluser]kashi[/eluser]
Hi again! haha still not working... i will tell you what i've done first of all i created a new controller called alphabet.php alphabet.php Code: <?php then i add this in my layout view (this worked fine) Code: <?php $this->load->helper('url'); and then i add this to config/routes.php Code: $route['alphabet/(:any)'] = 'letter/$1'; the result is: the alphabet menu appeared on the website, and when you click on a letter it links you to, for example, http://mysite.com/letter/a but that page gives me an 404 error. Oh and i created a new view called letters.php im totally lost, i dont know what to do, i hope you can help me! thanks so much! |
Welcome Guest, Not a member yet? Register Sign In |