[eluser]Unknown[/eluser]
I am completely new to CI so I'm still working my way through figuring our best practices.
I am building an app and I would like to load one of a couple different views based on the type of data being returned from the model. I have a table (toycat) and within that, a field named 'cattype'. I currently retrieve the data and tie it to
.
I want to load a different view file based on whether or not 'cattype' is 0,1,2 etc.
Should I write another function just to return the cattype and call it from the controller or should I just requery the model again? Not sure the best practice here. Code below:
Controller
Code:
function index($parent = null)
{
if ($parent == false)
{
$parent = 1;
}
//test
$this->load->model('category_model');
$data['cats'] = $this->category_model->getAllChildren($parent);
//seo data
$data['title'] = 'category page title here';
$data['description'] = 'Category description here...'; //passed to meta description tag
//end seo data
//send the user to the item view if the category they requested is an item list
if (//this is where the cattype code would go currently)
{
$data['content'] = 'category_item_view'; //this is the name of the view
} else {
$data['content'] = 'category_view'; //this is the name of the view
}
//load the view
$this->load->view('includes/template', $data);
}
And the model
Code:
//gets all child catagories
function getAllChildren($parent_id)
{
//get categories that are children of parent ID
$this->db->where('parent_id',$parent_id);
$query = $this->db->get('toycat');
if ($query->num_rows() > 0)
{
return $query->result();
}else{
return FALSE;
}
}
Thanks in advance!