Andy-H Posted May 24, 2012 Share Posted May 24, 2012 Does a controller necessarily have to invoke a Model or can I just invoke the view straight away or is it bad practice? <?php /** * Index * * Default controller, invokes when not query string is present * * @version 1.0 * @package com */ namespace com\controllers; class Index extends Abstract_Controller implements Interface_Controller { /** * Index::invoke * Invoke method required by Interface_Controller, output error message * @access public */ public function invoke(array $params) { $view = new \com\views\Index; $view->output('No method requested in query string'); return; } } Quote Link to comment https://forums.phpfreaks.com/topic/263054-vc/ Share on other sites More sharing options...
Andy-H Posted May 24, 2012 Author Share Posted May 24, 2012 I have changed the output method to a getContents method, which returns rather than echoing so only the controller outputs to the client, still unsure as to whether I need to invoke a model though, thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/263054-vc/#findComment-1348321 Share on other sites More sharing options...
Andy-H Posted May 24, 2012 Author Share Posted May 24, 2012 If anyone has a little spare time could they cast their eye over this and let me know if I'm doing things the right way, thanks . 18446_.zip Quote Link to comment https://forums.phpfreaks.com/topic/263054-vc/#findComment-1348334 Share on other sites More sharing options...
Kays Posted May 24, 2012 Share Posted May 24, 2012 Based on just what you have: 1. Better to name it class.* instead of *.class.php. 2. A controller shouldn't have a _getDBH() function. Makes more sense to have the model do whatever functionality you need. 3. Views shouldn't return a JSON encoded $data. Just display it on the spot. It can be pretty messy (and annoying) to look at any data that's in string format when you want to debug it later. Quote Link to comment https://forums.phpfreaks.com/topic/263054-vc/#findComment-1348444 Share on other sites More sharing options...
gizmola Posted May 25, 2012 Share Posted May 25, 2012 It pretty much depends on what the controller needs to do. If the controller needs to work with data, that is where models come into play. All the work you need to do with persisting or serializing data should be in models. You typically inject the model data into your views, so they can work with that data, but the view simply displays the data, or gathers user input. The models should always handle the persistinng of data, or querying etc. if that data is in a relational database. Quote Link to comment https://forums.phpfreaks.com/topic/263054-vc/#findComment-1348530 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.