title: Creating a Model Layer with PDO
body: <p>Im currently developing a MVC application Framework and I have come for some advise in regards to the way I should construct my Model Layers.</p>
  
  <p>The model is constructed so that each model is mapped to a table within the database for that applications, so a typical application would have</p>
  
  <ul>
  <li>Configuration</li>
  <li>Topics</li>
  <li>Forums</li>
  </ul>
  
  <p>and each would be mapped to there named PHP file such as <code>app/models/configuration.php</code></p>
  
  <p>Now the problem I am having is creating the parent database class to be able handle specific table data, for example:</p>
  
  <pre><code>class PDOModel
  {
      public function __construct()
      {
          $this-&gt;__Communicator = Registry::getPDOInstance();
      }
  
      public function getSingle($id)
      {
           return /*Row*/;
      }
  
      /*Etc*/
  }
  </code></pre>
  
  <p>And then something like this for the application model's</p>
  
  <pre><code>class Model_Topic extends PDOModel
  {
      protected $__id_column = 'id';
  }
  </code></pre>
  
  <p>and then within my controller I can use like so:</p>
  
  <pre><code>$Topic = $this-&gt;model-&gt;topic-&gt;get(22);
  </code></pre>
  
  <p>But i would also like to take into considerations auto joining tables as well, are there any simple lightweight libraries about that have been tested and fit the my requirements.</p>
  
  <p>Any help would be highly appreciated.</p>