Welcome Guest, Not a member yet? Register   Sign In
Get database results by slug?
#1

[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
#2

[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);
#3

[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);
[/quote]

Just out of curiosity -- I dont usually use uri->segment() -

I just do something like

Code:
function post($post_slug)
{
$data['query'] = $this->model->get_post($post_slug);
$this->load->view('single_post;, $data);
}

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?
#4

[eluser]Michael Wales[/eluser]
They do the same thing and the way you mention is my preferred way of doing things as well...




Theme © iAndrew 2016 - Forum software by © MyBB