Help With Product View issue with Template Library

#1
[eluser]JayArias[/eluser]
Ok, so I finall got around to understanding the template library. But i've still got some problems with my code.

Code:
class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->template->set_template('default');
        $this->template->write('title', "Default");
        $this->template->render();
    }
}

to show
Code:
$this->catalog->getLatest();
I have to place it in the view file or template.php file.

what I want to do is the following.
Code:
class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->template->set_template('default');
        $this->template->write('title', "Default");
                $this->template->write('content', $this->catalog->getLatest());
        $this->template->render();
    }
}
Yes, the code works but it doesn't appear in the correct spot it appears uptop before any of the code.

Here is my Model "Catalog"
Code:
<?php
Class catalog extends Model{
    function catalog()
    {
        parent::Model();
        $this->load->database('default');
    }
    function getLatest()
    {
        $query = $this->db->query("SELECT * FROM `products` WHERE `aprooved` = '1'");
        foreach($query->result() as $product)
        {
            echo "<ul>";
            echo "<li><a >category."/".$product->product_title."'><strong>".$product->product_title."</strong></a><br>";
            echo "<small>&nbsp;Submitted&nbsp;by&nbsp;<a >author."'>".$product->author."</a></small><br>";
            echo "<a >category."/".$product->product_title."'><img >product_thumbnail."'><a/></li>";
            echo "</ul>";
        }
    }
}

Please help.

#2
[eluser]Colin Williams[/eluser]
Your only confusion is with how PHP works. By echoing from the Model (and why are you generating markup in the model?) you are sending output directly to the browser, so it will logically appear before your template. You should simply return data from your model, then use a view to mark it up, then write that to the template.

#3
[eluser]JayArias[/eluser]
so
Code:
class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->template->set_template('default');
        $this->template->write('title', "Default");
        $data['catalog']= $this->catalog->getLatest();
        $this->template->write('content', $this->load->view('latest_cat', $data));
        $this->template->render();
    }
}


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.