How to echo in Model View Controller

I am new to MVC and I need to echo data from my database in View. Can anyone help me with that. Here is the code:

Controller:

[php]class Index extends Controller {

function __construct() {
parent::__construct();
//echo ‘We are in index’;
}

function index(){
$this->view->render(‘index/index’);
}

function get(){
$this->model->get();
}
}[/php]

Model:

[php]class Index_Model extends Model {

public function __construct()
{
parent::__construct();
}

function get()
{

$sth = $this->db->prepare('SELECT * FROM data');
$sth->setFetchMode(PDO::);
$sth->execute();
$sth->fetchAll();

}
}[/php]

How to echo data from database in View?

Use the controller to get data from the model and pass them on to the view. Example

[php]<?php

class ItemController
{
public function showList()
{
$items = $this->model->findAll();
$this->render(‘item/list’, $items);
}

public function showSingle($id)
{
$item = $this->model->findById($id);
$this->render(‘item/single’, $item);
}
}[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service