The twig:php view template engine, similar to the smart template engine.
: http://twig.sensiolabs.org/
Slim: Lightweight PHP MVC framework that can be used to build Web App,restful APIs similar to the flight framework.
: http://www.slimframework.com/
Configure the Slim+twig development environment:
Biz: Logical Business Layer
Common: Public level
Darjuan: third-party framework
Templates: View Template
Introducing Twig Extensions
Configure index.php
Require '/darjuan/slim/slim.php '; use \slim\slim as Slim; Slim::registerautoloader (); require '/darjuan/slim/extras/views/twig.php '; use Slim\views\twig as twigview; $app = new Slim (Array ( ' templates.path ' = __dir__. /templates ', ' debug ' = False, ' view ' = new Twigview);
Test Demo:
$app->group ('/layout ', function () use ($app) {$app->get ('/books ', function () use ($app) {$books [] =array (' id ' = >1003, ' title ' = ' news headline '); $app->render ('/books/books.list.php ', Array (' books ' = ' = $books));}); $app->get ('/books/:id ', function ($id) use ($app) {$book =array (' id ' = + $id, ' title ' + ' news headline 2 ', ' content ' = ') <a href= "#" >asdsadsadsa</a> "); # $app->view ()->setdata ($book); $app->render ('/books/books.detail.php ', $book);});
books.list.php
<! DOCTYPE html>
books.detail.php
<! DOCTYPE html>
Slim + Twig Building PHP Web application