Get database results by slug? |
[eluser]afterspark[/eluser]
Quick question. How would I go about returning a database result based on a slug at the end of my URL? The user guide shows that you should specifiy a row of the table, but I'm not sure how to do that when I'm using slugs instead of id's in my URL. Thanks
[eluser]Michael Wales[/eluser]
Let's assume your slug is segment 3 (like in this: domain.com/users/profile/walesmd) Code: $query = $this->db->getwhere('users', array('slug'=>$this->uri->segment(3)), 1, 0);
[eluser]fakeempire[/eluser]
[quote author="Michael Wales" date="1197669548"]Let's assume your slug is segment 3 (like in this: domain.com/users/profile/walesmd) Code: $query = $this->db->getwhere('users', array('slug'=>$this->uri->segment(3)), 1, 0); Just out of curiosity -- I dont usually use uri->segment() - I just do something like Code: function post($post_slug) So if you go to http://example.com/blog/post/this-is-post-name it will work. Is there anything wrong with this method vs the uri->segment or do they just do the same thing?
[eluser]Michael Wales[/eluser]
They do the same thing and the way you mention is my preferred way of doing things as well... |
Welcome Guest, Not a member yet? Register Sign In |