phongdatgl / smartyprovider
为silex提供的Smarty服务(不编译模板_c,多个变量分配)
dev-master
2014-12-10 10:18 UTC
Requires
- php: >=5.3.2
Requires (Dev)
- silex/silex: 1.0.2
- smarty/smarty: 3.1.21
This package is not auto-updated.
Last update: 2024-09-24 02:42:19 UTC
README
SmartyServiceProvider 为Silex创建provider,使用[Smarty] (https://smarty.php.ac.cn)作为twig的模板替代品
参数
-
smarty.class_path (字符串,可选): Smarty的libs目录路径。
-
smarty.options (数组,可选): 一些[Smarty] (https://smarty.php.ac.cn) API的选项。更多信息请参考:[Smarty文档] (https://smarty.php.ac.cn/docs/en/api.variables.tpl)
服务
- smarty: 使用
Smarty
模板引擎。具有适合Silex应用程序的定制选项。
安装
将[Smarty] (https://smarty.php.ac.cn)的路径放在vendor/Smarty
下。请确保其存在
use Phongdatgl\Smarty\ServiceProvider as SmartyServiceProvider; define('APP_PATH', '/path/your/project'); $app->register(new SmartyServiceProvider(), array( //'smarty.dir' => APP_PATH . '/vendor/Smarty/', //có hoặc không. Không có thì app sẽ mặc định lấy từ vendor 'smarty.options' => array( 'template_dir' => APP_PATH . '/views', 'caching' => false, 'force_compile' => false, 'use_sub_dirs' => false)));
使用
在silex中使用
$app->get('/hello/{name}', function ($name) use ($app) { $app['smarty']->assign('name', 'John Doe'); return $app['smarty']->render('hello.tpl', array('age'=>15)); });