I am new to Codeingiter and i am building a Simple Blog.
In Post table, i have “id, cat_id, title, content”… In category tablet i have “id, name”…
To display post,
i fetched contents from POST inside model using following function…
function get_posts(){
$query = $this->db->get('post');
return $query->result();
}
Then i load the view file to display the post… The above function fetch only the CATEGORY ID, but i need Category name… So i need to call model from view file… I think it is illogical to call Model from view… is there any solution???
Please help me…
Thank you
Try this as your model:
Do check if the table and column names in the join section are correct. ‘category’ is the name of your category table,
posts.category_id is the column in your posts table that refers to the category id, category.id is the id column in
the category table.
You should be able to access the category name now.