Set up

PIP is easy to set up and requires very minimal configuration. All you need do is download, check your .htaccess file, edit the config file, and off you go.

Installation

  • Download PIP and extract
  • Navigate to application/config/config.php and fill in your base_url
  • You are ready to rock! Point your browser to your base_url and hopefully see a welcome message.

.htaccess file

By default index.php is hidden in the URL. This is done using the .htaccess file in the root directory. The following .htaccess file works for me.

 <IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule . index.php [L]
  </IfModule>

    # Prevent file browsing
    Options -Indexes

Folder Structure

With MVC in mind the physical layout of PIP is fairly simple. Your application specific files go in the "application" folder (you don't need to touch the core folder). Inside the application folder there are folders for all of the specific application entities:

    /app
        /config
        /controllers
        /helpers
        /models
        /views
    /assets
        /css
        /images
        /js
    /core
    /vendor

When PIP loads files it assumes they are in the corresponding folders. So make sure you place your files in the correct folders.

Use the "assets" folder in the root to store you static resource files (CSS, JS etc) however you can put them anywhere. You can also use the URL helper functions to help include files in your HTML. For example:

    <link rel="stylesheet"
           href="<?php echo Url::asset('css/style.css'); ?>" 
           type="text/css" media="screen" />

Configuration

Before you start, edit the configuration file (app/config/config.php) to define your domain name, your database profile and any helpers or plugins that you want pre-loaded.

Set the base Url to your domain name, or your local test site:

    $config['base_url'] = 'http://localhost/appname/';

Set the default home controller and error controller:

    $config['default_controller'] = 'home'; 
    $config['error_controller']   = 'error';

Set the application namespace. All controllers, models and views in your application need to use this namespace:

    $config['app_namespace'] = 'app_name//'; 

Set the database PDO connection parameters:

    $config['database'] = array(
    'driver'   => 'mysql',
    'host'     => 'localhost',
    'database' => 'datbase_name',
    'username' => 'user_name',
    'password' => 'secret_password',
    'charset'  => 'utf8',
);

And finally, request any models, helpers or plugins to be pre-loaded (if required):

    $config['register'] = array( 
        'helpers/url',
        'helpers/auth',
        'helpers/session',
        'models/album',
        );

Naming Conventions

PIP's automatic RESTful routing works by following the naming conventions for Controllers and Actions. Please see the Controller section for more information.

All classes in PIP use camelCase naming. The associated file names must be the same except all lower case. So for example the class ThisClass would have the filename thisclass.php. Underscores in classes must be included in file names as well.