CodeIgniter Forums
Breaking the MVC convention, I think - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Breaking the MVC convention, I think (/thread-2536.html)



Breaking the MVC convention, I think - El Forum - 08-10-2007

[eluser]stevefink[/eluser]
Hi all,

I just realized I"m working on a simple application where I'm completely breaking the MVC convention. I keep doing everything using just controller/view, but lack models. I'm certain my views are okay as they're all just markup and have a few foreach clauses using very light PHP. Can anyone take a look at this controller class and tell me if any of it belongs in the model according to good practices?

---

<?php

class Meduser extends Controller {

// db resource handlers
private $db_users;
private $db_notes;

function Meduser()
{
parent::Controller();
$this->db_users = $this->load->database('medusers', TRUE);
$this->db_notes = $this->load->database('mednotes', TRUE);
}

function index()
{
// load view.
$this->load->view('default/meduser_view');
}

function check_pending_users()
{
// retrieve all records.
$data['query'] = $this->db_users->query('select * from tbl_signups
where hostname = \'\''
);

// view for pending users container div.
$this->load->view('default/meduser_pu_view', $data);
}
}

?>

--

Thank you kindly.


Breaking the MVC convention, I think - El Forum - 08-11-2007

[eluser]Freakish_05[/eluser]
Strictly speaking, your database query should be in a model file. But there really isn't much point for such a small query. In the 'blog' video tutorial the narrator put his database queries into the controller file as well, but they were very short and simple like yours.

IIRC models are there to make complex queries more accessible to the rest of the application.

If I'm wrong I'm sure one of the more experienced CI users will be along shortly to correct me Smile

HTH,
Freakish_05


Breaking the MVC convention, I think - El Forum - 08-11-2007

[eluser]esra[/eluser]
MVC is not strictly enforced by CI. In fact, I believe that the original version had no support for models. Coding as you are could be considered a matter of preference when using CI, but it does not conform with the MVC paradigm.


Breaking the MVC convention, I think - El Forum - 08-12-2007

[eluser]Michael Wales[/eluser]
What you are doing is fine, according to CI's standards - as models are optional. It's best to rethink some of your queries and design them so that they can be reusable amongst your many controllers - then toss those queries into your models. It will save you a lot of time in the long-run.