Database, Illuminate, Laravel, Micro Framework, MVC, PHP

Quick Development: Slim Framework + Illuminate(Laravel)

Create a project folder and add a composer.json file in it and paste the following codes, and run composer install. You should have Slim Framework, Twig, Illuminate(Laravel) in the project folder.

{
    "name": "Quick Dev!",
    "require": {
        "php": ">=5.3.0",
        "slim/slim": "2.*",
        "slim/extras": "2.*",
        "twig/twig": "1.*",
        "illuminate/database": "*"
    },
    "autoload": {
        "classmap": [
            "models"
        ]
    }
}

Add a index.php file in project folder and copy paste the following:

<?php

require 'vendor/autoload.php';

// Database information
$settings = array(
    'driver' => 'mysql',
    'host' => '127.0.0.1',
    'database' => 'dbname',
    'username' => 'username',
    'password' => 'password',
    'collation' => 'utf8_general_ci',
    'prefix' => '',
    'charset' => 'utf8'
);

// Bootstrap Eloquent ORM
$container = new IlluminateContainerContainer;
$connFactory = new IlluminateDatabaseConnectorsConnectionFactory($container);
$conn = $connFactory->make($settings);
$resolver = new IlluminateDatabaseConnectionResolver();
$resolver->addConnection('default', $conn);
$resolver->setDefaultConnection('default');
IlluminateDatabaseEloquentModel::setConnectionResolver($resolver);

$app = new SlimSlim();

$app->get('/', function () {
    echo "<h1>Quick Dev!!</h1>";
    $articles = Article::all();
    echo $articles->toJson();
});

$app->run();

Create a folder named models in the project folder and add the following into a file named Article.php:

<?php

class Article extends IlluminateDatabaseEloquentModel
{

}

Don’t forget our .htaccess file in a project folder. 🙂

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

Now you can navigate to your system, for example: http://localhost/quick-dev

p/s: You can use Twig later on. 🙂

Reference: http://revul.es/slim/#/60

Leave a Reply

Your email address will not be published. Required fields are marked *

fourteen − 2 =