Welcome Guest, Not a member yet? Register   Sign In
Breaking the MVC convention, I think
#1

[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.
#2

[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
#3

[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.
#4

[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.




Theme © iAndrew 2016 - Forum software by © MyBB