Welcome Guest, Not a member yet? Register   Sign In
Help please
#1

[eluser]Fr334Ever[/eluser]
hi there ,
I have a little problem :
I have this controler :

Code:
<?php
class C_related extends Controller
{
    function related1()
    {
        $this->load->model('m_related');
        $data['rel'] = $this->m_related->getAll();
        
        $this->load->view('produse/v_product', $data);
    }
}
?>
and this model

Code:
<?php
class M_related extends Model
{
   function getAll()
   {
           $this->db->limit(3);
        $q = $this->db->get('product');
        
        if($q->num_rows() > 0)
        {
            foreach ($q->result() as $row)
            {
                $data[] = $row;
            }
            return $data;
        }
    }
}

?>
and this view
Code:
<html>
  <body>
    <div id="cat1">
        <p>Related</p>
        
        &lt;?php foreach($rel as $r) : ?&gt;
        &lt;?php echo $r->name; ?&gt;</br>
        &lt;?php endforeach; ?&gt;
    </div>
  &lt;/body&gt;
&lt;/html&gt;

I wanth to put the v_related in to another view like : products/prod.php , and I tried an I kand fetch any data , when I test the controller it works bunt when I put this

&lt;?php
                                                        $data = array('rel' => $r->name);
                                                        $this->load->view('v_related', $data);
                                                        print_r($data);
?&gt;

in tot he othen view I don' see anithing .
Please help
#2

[eluser]toopay[/eluser]
If you doesn't use some fancy template engine, you can do this way too :
Code:
// In model :
function getAll()
{
   q = $this->db->limit(3)->get('product');
   return $q->num_rows() > 0 ? $q->result_array() : array();
}

// In controler :
$data['rel'] = $this->m_related->getAll();
$some_section = $this->load->view('v_related', $data, TRUE); // This will contain your related section
$data['some_section'] = $some_section;
// Output everything in your template/main view
$this->load->view('produse/v_product', $data);

// In your view :
&lt;html&gt;
&lt;head&gt;
&lt;!-- head section --&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;!-- body section --&gt;

&lt;!-- start some section --&gt;
   <h3>Some section</h3>
   &lt;?php echo $some_section ?&gt;
&lt;!-- end some section --&gt;
&lt;/body&gt;
&lt;/html&gt;
One more thing, remove php closing tags '?&gt;' from your controller and model class.




Theme © iAndrew 2016 - Forum software by © MyBB