Adding twig in slim framework

Ok, here how i worked to implement this,

First i added twig in require section of composer.json

"twig/twig":"*"

then i update my vendor using composer update.

after that, in my index.php, i added the following lines

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

note that, i am storing my view files in application/views folder and will store cache in cache folder.

at this point, i created a test route

$app->get('/twig',function(){
    global $twig;
    $data = array('inp'=>1);
    echo $twig->render('twig_test.twg.php', $data);

});

the view file (twig_test.twg.php) is pretty simple,  i just added this line in view file to test that my twig configuration is working well.

{{inp}}

then finally, boot up the php development server using php-S and went to localhost/twig to confirm that twig is working with slim framework

Advertisements

CodeIgniter is Great

Codeigniter is great to understand and learn. If you consider CI,Cake PHP or symfony, you will see that CI is easy. I learned it when i was a student of university.
Now the point is Although CI is easy to learn, But i Think symfony has a lot of option to do. Symfony has the support of twig and doctrine. Which makes it a true framework.
Now lets point on the size. Codeigniter is small, really small, and have Active Record support. But CI don’t have YAML support i think.
Symfony 2 has the support of YAML but it is not as light as CI.

I still prefer CI , Cause support is the best option to determine a framework.