purplebabar / twiger
轻量级集成框架
1.0.11
2015-03-08 00:00 UTC
Requires
- php: >=5.3.0
- j4mie/idiorm: ~1.5
- mustangostang/spyc: 0.5.*
- purplebabar/twiger-core: 1.0.*
- twig/twig: ~1.18
README
一个简单的集成框架
Twiger 是 twig 的独立实现,允许您集成网站并使其 100% 适用于 symfony。
安装
要安装 Twiger,只需打开终端,通过 composer 安装:php composer create-project purplebabar/twiger nameOfYourProject。您的服务器需要指向您的文件夹,app.php 文件将完成其余工作;)
配置
在 app/config/config.yml 中,您可以根据需要配置存储您资产的文件夹,只需填写以下内容:
assets: nameOfYourFolder
函数
添加了两个函数到 twig 的默认函数中
assets(path)
The assets function return the path to the assets folder, just add the end of the path. (ex.: yourassets folder is named *assets*, the functino will return you */assets/*
path(routeName, args)
The path function return the patter of the route filled with the args you gae in args.
模板
您的模板必须位于 src/templates 目录中
路由
关于路由,您有多种选择。您可以定义控制器或模板进行直接渲染。
模板
second: pattern: /foo template: bar
此语法会在服务器上触发 /foo 时自动渲染位于模板目录中的 bar.html.twig 模板
控制器
home: pattern: /foo/{bar} controller: IndexController::foo
此语法将调用位于项目 src/control 的 IndexController 中的 foo 函数。参数 bar 将传递给该函数。
控制器
您的控制器必须按以下方式定义
<?php namespace control; require_once __DIR__."/../../vendor/autoload.php"; use twiger\Twiger as Twiger; class IndexController extends Twiger{ public function foo($bar){ return $this->render('bar.html.twig', array('bar' => $bar)); } }
这样,您就可以使用 Twiger 了,让它咆哮吧 ;)