ramplstilskin Posted November 13, 2017 Share Posted November 13, 2017 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(); } } How to echo data from database in View? Quote Link to comment Share on other sites More sharing options...
requinix Posted November 14, 2017 Share Posted November 14, 2017 You know your code doesn't work, right? The View is where all output goes. The Controller should get whatever data the View needs (from the Model), then passes it to the View. How you do that depends on your MVC framework so check their documentation. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.