title: Using Composer Packages with Slim PHP 2.0
body: <p>I am trying to build a REST API using Slim PHP 2.0, Composer, and a couple third-party packages. I used Composer to install Slim by creating a composer.json file in the root of my application with the following:</p>
  
  <pre><code>{
      "require": {
          "slim/slim": "2.*"
      }
  }
  </code></pre>
  
  <p>After I ran composer install I have the following structure:</p>
  
  <pre><code>root/
      vendor/
          composer/
          slim/
          autoload.php
      composer.json
      composer.lock
      index.php
  </code></pre>
  
  <p>I want to include the Valitron (<a href="https://packagist.org/packages/vlucas/valitron" rel="nofollow">https://packagist.org/packages/vlucas/valitron</a>) library to do validation along with this Bcrypt (<a href="https://packagist.org/packages/openlss/func-bcrypt" rel="nofollow">https://packagist.org/packages/openlss/func-bcrypt</a>) library to hash passwords for users. So, I made the following additions to my composer.json file so the it looks like this:</p>
  
  <pre><code>{
      "require": {
          "slim/slim": "2.*",
          "vlucas/valitron": "dev-master",
          "openlss/func-bcrypt": "dev-master"
      }
  }
  </code></pre>
  
  <p>After I ran composer update I got the following directory structure. </p>
  
  <pre><code>root/
      vendor/
          composer/
          openlss/
          slim/
          vlucas/
          autoload.php
      composer.json
      composer.lock
      index.php
  </code></pre>
  
  <p>From here, I am not sure how to set up the autoloading for my application. I sometimes see autoload classmap and other times see psr-0. On top of these third-party packages I am going to be creating my own models to use. One will be a base model that handles connecting to the database and then each table will have a model that I use to manipulate the said table with. So for interacting with the users table I will use my UserModel.php file below. My other question is how would I go about "using" the Valitron and BCrypt files within this one? Would I just do this:</p>
  
  <pre><code>&lt;?php namespace Libraries;
  
  use \Valitron;
  use \BCrypt;
  
  class UserModel extends BaseModel {
  
      // I want to use the Valitron class here along with the crypt file
  
  }
  </code></pre>
  
  <p>How would I go about setting up autoloader to accomplish this? Any help is greatly appreciated. I already dislike Composer a lot but since everyone is saying it's a must for PHP developers I am trying to force myself to learn it.</p>