Quick, easy, quick :: Slim, Twig, RedBean

I wanted to create one very quick and minimalist PHP environment what contain one PHP framework, one ORM and one template engine. My dream was that the selected framework should be quick, it must support Composer. I was looking for that ORM one is very quick and it support Composer and I was looking for template engine which support caching and it is complex and it has simple template syntax. And I had one more condition that each component have to support PHP namespaces and have to working with PHP 5.3 or higher version.

So, my choice are these tools:

Slim PHP Framework

Why? I think Slim is a very clean and well-designed PHP framework. It has good routing subsystem and it support PHPUnit. And it is very mini and quick.

URL: http://www.slimframework.com/

Twig template engine

Why? I guess Twig is the best PHP Engine now it has well-designed cache system and template syntax.

URL: http://twig.sensiolabs.org/

RedBean ORM

Why? RedBean is easy, complex and very quick ORM it is real lightweight ORM.

URL: http://redbeanphp.com/

How?

I was installing each component with the composer. My composer.json file is something like this:

First I created new project’s direcory.

 mkdir test_project  

I created my composer.json file.

 {  
   "require": {  
     "slim/slim": "2.*",  
     "twig/twig": "1.*",  
     "gabordemooij/redbean": "*"  
   }  
 }  

I updated my project with composer.

 sudo php composer.phar update  

And I created the simple test project.

 <?php  
 require 'vendor/autoload.php';   

 use RedBean_Facade as RedBean;  

 Twig_Autoloader::register();  

 $app = new \Slim\Slim();  

 $app->get('/hello/:name', function ($name) {  

      RedBean::setup('mysql:host=localhost;  
     dbname=test','user','password');  

      $loader = new Twig_Loader_Filesystem('templates');  
      $twig = new Twig_Environment($loader, array(  
        //'cache' => 'cache',  
      ));  

       $row = RedBean::getRow( 'SELECT * FROM book WHERE id = :id',   
     array(':id'=>7)   
   );  

      echo $twig->render('test.html', array('book_title' => $row['title']));  

 });  

 $app->run();  

Well, I created cache directory and template directory and test.html template file.

 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
 <html>  
 <head>  
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
 <title>My first test page</title>  
 </head>  
 <body>  
   {{ book_title }}  
 </body>  
 </html>  

and the test URL

 http://localhost/test_project/test.php/hello/john  

Thats it. I think these tools are really has high quality and the PHP is a consistent programming language. You can use PHPUnit, PHPCode_Sniffer and more programming tools which make better your coding standards.

About these ads

About janosvajda

I am a PHP, Symfony, Node.js developer.
This entry was posted in Uncategorized and tagged , , , , , . Bookmark the permalink.

4 Responses to Quick, easy, quick :: Slim, Twig, RedBean

  1. I love Readbean – I mashed it up with SlimPHP for easily extending the RESTful bit, used R::graph a lot and have shaved hours of cruft off my dev time with a simple easy to populate DB API.

  2. vanting says:

    I created a project named RedSlim which is a pre-configured development environemnt using Slim, Twig, Redbean and Bootstrap. The code is hosted in github (https://github.com/vanting/RedSlim), and you can deploy it to the pagodabox cloud (the slim hosting) within a minute.

  3. Pingback: Quick, easy, quick :: Slim, Twig, RedBean | tediscript.wordpress.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s