1 Replies - 344 Views - Last Post: 13 November 2017 - 12:14 PM Rate Topic: -----

#1 zatoichi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 24-August 17

Echoing in Model View Controller

Posted 13 November 2017 - 11:53 AM

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:
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();
}
}


Model:
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();
}
}
:code:

How to echo in View data taken from database in Model? Thanks

This post has been edited by modi123_1: 13 November 2017 - 11:54 AM
Reason for edit:: In the future, please use the [code] tag button in the editor.


Is This A Good Question/Topic? 0
  • +

Replies To: Echoing in Model View Controller

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4140
  • View blog
  • Posts: 13,094
  • Joined: 08-June 10

Re: Echoing in Model View Controller

Posted 13 November 2017 - 12:14 PM

Quote

How to echo in View data taken from database in Model?

That depends on the View implementation, which you have not shown here.

However, that requires the Controller to pass the Modelís data into the View.

Note: you can omit these empty constructors:
public function __construct()
{
    parent::__construct();
}


PHP automatically calls the first constructor it finds in the inheritance chain.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1