Welcome Guest, Not a member yet? Register   Sign In
url segment
#2

[eluser]umefarooq[/eluser]
hi first keep your model clean only for database functions. get you all url segments in controller and pass to you model functions.

controller
Code:
<?php

class Category extends Controller {

    function Category()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $data['title'] = "Category";
        $category = $this->uri->segment(2);
        $data['item'] = $this->Post->get_posts_by_category($category);
        
        $this->load->view('meta', $data);
        $this->load->view('header', $data);
    }
}

model
Code:
function get_posts_by_category($category)
    {
        $this->db->select('*');
        $this->db->where('category', $category);
        
        $query = $this->db->get('post');
        return $query->result_array();
    }

also debug it with echo $category in controller that you are getting proper value in you uri segment or not.


Messages In This Thread
url segment - by El Forum - 10-19-2009, 05:27 AM
url segment - by El Forum - 10-19-2009, 05:47 AM
url segment - by El Forum - 10-19-2009, 05:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB