Slim + Twig Building PHP Web application

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.