Reputation: 165
I am using codeigniter's MVC and I am building an app where users can create their own pages where they get to write about their hobbies ( cars, books and movies) for other people to read.
When you go on a user's page, you should be able to see their topics ( writing about cars for example).
I am having trouble fetching the data for each page, from the mysql table. I have a good understanding of codeigniter's MVC when passing user id to a function from the view page (using a button) to the model page.
However, I dont know how to load data of a page based on a user's id.
Any examples of the MVC structure would be much appreciated.
Here is what I mean in the picture below
THanks in advance
Upvotes: 2
Views: 191
Reputation: 650
From your VIEW file, in href, pass the created_page_id like this
<a href="<?php echo base_url()?>controller/function/<?php echo $value_of_created_page_id?>"></a>
Now in the controller, your function should be something like
function function_name()
{
$created_page_id = $this->uri->segment(3); //this is how you get the id
if($created_page_id != '')
{
// pass page_data to your view page now using query.
//do some extra things if needed.
$page_data['view_result'] = $this->Your_Model_Name->your_model_function_name();
$this->load->view('your_page_name',$page_data);
}
else
{
redirect(base_url(),'refresh');
}
}
Now in view page, show data from the variable passed name $view_result;
Upvotes: 1