Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As frameworks templates go, I find the MVC pattern to be one of the most "loosely coupled" ways of building an application.</p> <p>Think of the relationships like interfaces, or contracts between the parts of the application. The Model promises to make this data available to the View and the Controller. No one cares exactly <em>how</em> the Model does that. It can read and write from a typical DBMS, like MySQL, from flat files, from external data sources like ActiveResource, as long as it fulfills its end of the deal.</p> <p>The Controller promises to make certain data available to the View, and relies on the Model to fulfill its promises. The view doesn't care <em>how</em> the Controller does it.</p> <p>The View assumes that the Models and the Controllers will keep their promises, and can then be developed in a vacuum. The Model and Controller don't care if the view is generating XML, XHTML, JSON, YAML, plaintext, etc. They are holding up their end of the contracts.</p> <p>And, of course, the View and the Controller need to agree that certain things exist. A View without some corresponding Controller activity might work fine, but could never be used. Even if the Controller doesn't <em>do</em> anything, as might be the case in static pages:</p> <pre><code>&lt;?php class StaticController extends ApplicationController { /** * Displays our "about" page. */ public function about () { $this-&gt;title = 'About Our Organization'; } } </code></pre> <p>Then the associated View can just contain static text. (Yes, I have implemented things like this before. It's nice to hand a static View to someone else and say "Just write on this.")</p> <p>If you look at the relationships between the M, V, and C as contracts or interfaces, MVC suddenly looks very "loosely coupled." Be wary of the lure of stand-alone PHP files. Once you start including and requiring a half-dozen .inc files, or mixing your application logic with your display (usually HTML) you may have coupled the individual pages more loosely, but in the process made a mess of the important aspects.</p> <pre><code>&lt;?php /** * Display a user's profile */ require_once 'db.php'; $id = $db-&gt;real_escape_string($_GET['id']); $user_res = $db-&gt;query("SELECT name,age FROM users WHERE id = $id;"); $user = $user_res-&gt;fetch_assoc(); include 'header.php'; ?&gt; &lt;h1&gt;&lt;?php echo $user['name']; ?&gt;'s Profile&lt;/h1&gt; &lt;p&gt;&lt;?php echo $user['name']; ?&gt; is &lt;?php echo $user['age']; ?&gt; years old!&lt;/p&gt; &lt;?php include 'footer.php'; ?&gt; </code></pre> <p>Yeah, "profile.php" and "index.php" are completely unrelated, but at what cost?</p> <p><strong>Edit:</strong> In response to your edit: Push for MVC. You say you have "half-programmers," and I'm not sure which half (do you have front-end people who are good at HTML and CSS but not at server-side? writers with some programming experience?) but with an MVC framework, you can hand them just the views, and say "work on this part."</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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