Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP MVC & SQL minus Model
    text
    copied!<p>I've been reading several articles on MVC and had a few questions I was hoping someone could possibly assist me in answering.</p> <p>Firstly if <strong>MODEL</strong> is a representation of the data and a means in which to manipulate that data, then a Data Access Object (DAO) with a certain level of abstraction using a common interface should be sufficient for most task should it not?</p> <p>To further elaborate on this point, say most of my development is done with MySQL as the underlying storage mechanism for my data, if I avoided vendor specific functions -- (i.e. UNIX_TIMESTAMP) -- in the construction of my SQL statements and used a abstract DB object that has a common interface moving between MySQL and maybe PostgreSQL, or MySQL and SQLite should be a simple process.</p> <p>Here's what I'm getting at some task, are handled by a single <strong>CONTROLLER</strong> -- (i.e. UserRegistration) and rather that creating a <strong>MODEL</strong> for that task, I can get an instance of the db object -- (i.e. DB::getInstance()) -- then make the necessary db calls to INSERT a new user. Why with such a simple task would I create a new <strong>MODEL</strong>?</p> <p>In some of the examples I've seen a <strong>MODEL</strong> is created, and within that <strong>MODEL</strong> there's a SELECT statement that fetches x number of orders from the order table and returns an array. Why do this, if in your <strong>CONTROLLER</strong> your creating another loop to iterate over that array and assign it to the <strong>VIEW</strong>; ex. 1?</p> <blockquote> <p>ex. 1: <code>foreach ($list as $order) { $this-&gt;view-&gt;set('order', $order); }</code></p> </blockquote> <p>I guess one could modify the return so something like this is possibly; ex. 2.</p> <blockquote> <p>ex. 2: <code>while ($order = $this-&gt;model-&gt;getOrders(10)) { $this-&gt;view-&gt;set('order', $order); }</code></p> </blockquote> <p>I guess my argument is that why create a model when you can simply make the necessary db calls from within your <strong>CONTROLLER</strong>, assuming your using a DB object with common interface to access your data, as I suspect most of websites are using. Yes I don't expect this is practical for all task, but again when most of what's being done is simple enough to not necessarily warrant a separate <strong>MODEL</strong>.</p> <p>As it stands right now a user makes a request 'www.mysite.com/Controller/action/args1/args2', the front controller (I call it router) passes off to Controller (class) and within that controller a certain action (method) is called and from there the appropriate <strong>VIEW</strong> is created and then output.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload