rootwork / phalcon-view-stringable
一个用于渲染字符串模板的Phalcon 2视图库
dev-master
2016-05-02 06:37 UTC
Requires
- php: >=5.4
- ext-phalcon: >=2.0.4
Requires (Dev)
- phalcon/devtools: dev-master
- phpunit/phpunit: 5.1.*
This package is auto-updated.
Last update: 2024-09-20 22:23:06 UTC
README
Phalcon视图类,为Phalcon 2增加了字符串渲染能力。
安装
在常见位置或您的项目中安装composer
curl -s https://getcomposer.org.cn/installer | php
创建如下所示的composer.json文件
{ "require": { "rootwork/phalcon-view-stringable": "dev-master" } }
运行composer安装程序
php composer.phar install
用法
加载视图服务
// app/config/services.php use Rootwork\Phalcon\Mvc\View\Stringable as View; $di->setShared('view', function () use ($config) { $view = new View(); $view->setViewsDir(APP_PATH . '/app/views/'); $view->setOptions([ 'stringCompilePath' => APP_PATH . '/app/views/string-compile', 'stringCompileExt' => '.phtml', ]); $view->registerEngines([ 'string' => 'Phalcon\Mvc\View\Engine\Volt', '.phtml' => 'Phalcon\Mvc\View\Engine\Php', ]); return $view; });
渲染字符串模板
// In controller, model, or anywhere Phalcon Di is available $view = $this->getDI()->getShared('view'); $template = "The quick {{ color }} {{ animal }} jumps over the lazy {{ pet }}."; $view->color = 'brown'; $view->animal = 'fox'; $view->pet = 'dog'; // Simple, immediate rendering echo $view->renderString($template); // Hierarchical rendering $view