title: how to structure MVC models and ORM models
body: <p>I have some trouble getting a good folder structure in my project and i would like to know what other ways i could use to structure my files.</p>
  
  <p>I'm currently working in an MVC sturctured folder.</p>
  
  <pre><code>www/
    Controllers/
    Models/
    Views/
  </code></pre>
  
  <p>Nothing special so far. But i'm also using an ORM system. With it i can easily get an 'object' from my database like:</p>
  
  <pre><code>ORM::load('table');
  </code></pre>
  
  <p>Now this sort of code should reside in a Model right? So i'd get something like this:</p>
  
  <pre><code>&lt;?php
  class userModel
  {
      public function getAllUsers ( )
      {
          return ORM::load('table');
      }
  
      public function getUserById ( $id )
      {
          return ORM::load('table', 'userid=?', array($id));
      }
  }
  ?&gt;
  </code></pre>
  
  <p>Looks good so far in my opinion... But there's one more thing. I can also specify a 'model' when using the ORM system. With this model i can basically set up validation rules. Like so:</p>
  
  <pre><code>ORM::withModel('authModel');
  </code></pre>
  
  <p>This lets the ORM know that before it adds a new row (or updates an existing one) to the DB, that it should check the following model first for validation rules.</p>
  
  <pre><code>&lt;?php
  class authModel //Or maybe authValidation??
  {
      // Method gets automatically triggered when an update is done with the ORM
      public function onUpdate ( $obj )
      {
          if ( $obj-&gt;username == '' )
              throw new \Exception('No username');
      }
  
      public function onInsert ( $obj )
      {
          // Validations here too.
      }
  }
  ?&gt;
  </code></pre>
  
  <p>Now the problem is, is that i have 2 sorts of models. One where i basically use getters/setters to get and store data to the database (from my controller to my model).</p>
  
  <p>And i have another model in which validation rules are set... I don't want to mix both in the same folder. So i must come up with another structure for this. Something like:</p>
  
  <pre><code>www/
    Controllers/
    Models/
      Repositories/
      Entities/
    Views/
  </code></pre>
  
  <p>It's just that my model isn't a real 'repository', since it doesn't store any objects in the repo class and doesn't have a commit() method or anything like that.</p>
  
  <p>I also can't store the 2nd model (for validations) in the Entities folder, because they're not Entities at all...</p>
  
  <p>Any idea how i should structure this..??</p>