Welcome Guest, Not a member yet? Register   Sign In
Detail content page, showing content
#1

[eluser]Michal1[/eluser]
Hello,

I have been trying to make a simple cms and have a little problem. Right now I am working on detail content page which is shown when somebody click on the "read whole entry" on the main page.

So basically what I want to have in this detail content page is to show just a article which has been opened.

So I have a view detail_view and inside

Code:
<?php if (isset($records)) : foreach($records as $row) : ?>



<p> &lt;?php echo $row->content; ?&gt; </p>



&lt;?php endforeach ;?&gt;

&lt;?php else : ?&gt;

Nothing

&lt;?php endif; ?&gt;

Then in site controller I have a function detail

Code:
function detail()
    
    {
        
        $datad = array();
        $product_id = $this->uri->segment(3);
        if ($query = $this->site_model->get_records())
        
        {
            $this->db->where('id',$product_id);
            $datad['records'] = $query;
            
        }
        
        $this->load->view('detail_view', $datad);
    }

So basically I want to grab a article where id is match with url 3 segment which is a id of an article.

But when my article (detail page is opened) instead of concrete article I get all article from database. And dont know why.

Anybody has any ideas?

my model looks like this:

Code:
class Site_model extends Model

{
    
    function get_records()
    
    {
        
        $this->db->order_by("id", "desc");
        $query = $this->db->get('data');
        
        return $query->result();
    }
    
}
#2

[eluser]Michal1[/eluser]
Huh, nobody?:/
#3

[eluser]Cristian Gilè[/eluser]
The
Code:
$this->db->where('id',$product_id);

should be in the function model not in the controller.

You have also to pass the product_id to the model function:

Code:
if ($query = $this->site_model->get_records($product_id))
{
....
....

and your model function function needs a parameter and some changes:

Code:
function get_records($product_id)
    
    {
        
        $this->db->where('id',$product_id);
        $query = $this->db->get('data');
        
        return $query->row();
    }

The code still needs some logical and stylish changes but it should work.


Cristian Gilè




Theme © iAndrew 2016 - Forum software by © MyBB