PIP is a tiny PHP application framework built for people who use a LAMP stack. PIP aims to be as simple as possible to set up and use.



You can download the latest version of PIP in either zip or tar formats.

You can also clone the project with Git by running:

$ git clone git://github.com/gilbitron/PIP



PIP is very similar in it's architecture to CodeIgniter and will likely look very familiar to you if you already have experince with CodeIgniter. However remember that PIP is a tiny framework and does not include a lot of the functionality that comes with CodeIgniter.


PIP is based on the Model-View-Controller development pattern. MVC is a software approach that separates application logic from presentation. In practice, it permits your web pages to contain minimal scripting since the presentation is separate from the PHP scripting.

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 system folder). Inside the application folder there are folders for all of the specific application entities:

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

We encourage you to use the "static" folder in the root to store you static resource files (CSS, JS etc) however you can put them anywhere. You can also use the BASE_URL variable to help include files in your HTML. For example:

<link rel="stylesheet" href="<?php echo BASE_URL; ?>static/css/style.css" type="text/css" media="screen" />

Naming Conventions

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

URL Structure

By default, URLs in PIP are designed to be search-engine and human friendly. Rather than using the standard "query string" approach to URLs that is synonymous with dynamic systems, PIP uses a segment-based approach:


By default index.php is hidden in the URL. This is done using the .htaccess file in the root directory.


Controllers are the driving force of a PIP application. As you can see from the URL structure, segments of the URL are mapped to a class and function. These classes are controllers stored in the "application/controller" directory. So for example the URL...


...would map to the following Controller with the filename auth.php:


class Auth extends Controller {

    function index()
        // This is the default function (i.e. no function is set in the URL)
    function login()
        echo 'Hello World!';



...and the output would be "Hello World!".

The default controller and error controller can be set in application/config/config.php

Note that if you need to declare a contructor you must also call the parent constructor like:


class Example extends Controller {

    public function __construct()
        // Your own constructor code



There are several helper functions that can also be used in controllers. Most of these functions take the parameter $name of the corresponding class:


In PIP a view is simply a web page. They can contain everything a normal web page would include. Views are almost always loaded by Controllers. So for example if you had a view called main_view.php that contained the following HTML:

<title>My Site</title>
    <h1>Welcome to my Site!</h1>

... you would load it in a controller by doing the following:


class Main extends Controller {
    function index()
        $template = $this->loadView('main_view');


The View class has a helper function called set($key, $val) that allows you to pass variables from the Controller to the View.

$template = $this->loadView('main_view');
$template->set('someval', 200);

...then in the view you could do:

<?php echo $someval; ?>

...and the output would be 200. Any kind of PHP variable can be passed to a view in this way.


In PIP models are classes whose sole responsiblity it is to deal with data (usually from a database). For example:


class Example_model extends Model {
    public function getSomething($id)
        $id = $this->escapeString($id);
        $result = $this->query('SELECT * FROM something WHERE id="'. $id .'"');
        return $result;


...then in a controller you would do:
function index()
    $example = $this->loadModel('Example_model');
    $something = $example->getSomething($id);
    $template = $this->loadView('main_view');
    $template->set('someval', $something);

Now the results of your database query would be available in your view in $someval. Note that in the above code there are no steps to connect to the database. That is because this is done automatically. For this to work you must provide your database details in config.php:

$config['db_host'] = ''; // Database host (e.g. localhost)
$config['db_name'] = ''; // Database name
$config['db_username'] = ''; // Database username
$config['db_password'] = ''; // Database password

There are several helper functions that can also be used in models:

Helpers & Plugins

There are two types of additional resources you can use in PIP.


Thanks to the following people for contributing to PIP:


v0.5.3 - Several changes:

v0.5.2 - Several changes:

v0.5.1 - Several changes:

v0.5 - Initial version.

PIP Contents

Fork me on GitHub