项目作者: justmd5

项目描述 :
twig template for yaf
高级语言: PHP
项目地址: git://github.com/justmd5/yaf-twig-adapter.git
创建时间: 2016-04-25T03:21:06Z
项目社区:https://github.com/justmd5/yaf-twig-adapter

开源协议:

下载


yaf-twig-adapter

FOSSA Status

Twig Adapter for Yaf PHP Framework with namespace enabled.

Installation

You can install via Composer.

At first create composer.json file:

  1. {
  2. "require": {
  3. "justmd5/yaf-twig-adapter":">=1.0"
  4. }
  5. }

Run composer to install.

  1. $ composer install

Finally, include vendor/autoload.php at index.php

  1. require_once 'vendor/autoload.php';

Add to Bootstrap.php:

  1. <?php
  2. use \Yaf\Bootstrap_Abstract;
  3. use \Yaf\Dispatcher;
  4. use \Yaf\Application;
  5. use \JustMd5\TwigAdapter;
  6. class Bootstrap extends Bootstrap_Abstract
  7. {
  8. /**
  9. * @param Dispatcher $dispatcher
  10. */
  11. protected function _initTwig(Dispatcher $dispatcher)
  12. {
  13. $config = Application::app()->getConfig();
  14. $dispatcher->setView(new Twig(APP_PATH.'views', $config->twig->toArray()));
  15. }
  16. }

Add to application.ini:

  1. [product]
  2. ;app
  3. application.view.ext = twig
  4. ;twig
  5. twig.cache = APP_PATH "../cache"
  6. [devel : product]
  7. ;twig
  8. twig.debug = true

如果你的项目中存在modules则可以参考如下:

  1. <?php
  2. use \Yaf\Bootstrap_Abstract;
  3. use \Yaf\Dispatcher;
  4. use \Yaf\Application;
  5. use \JustMd5\TwigAdapter;
  6. class Bootstrap extends Bootstrap_Abstract
  7. {
  8. /**
  9. * @param Dispatcher $dispatcher
  10. */
  11. public function _initTwig(Dispatcher $dispatcher)
  12. {
  13. if (REQUEST_METHOD !== 'CLI') {
  14. $config = Application::app()->getConfig();
  15. $modules_names = explode(',', $config->application->modules);
  16. $paths = [ROOT_PATH . '/' . APP_NAME . '/views'];
  17. array_walk($modules_names, function ($v) use (&$paths) {
  18. if (is_dir(ROOT_PATH . '/' . APP_NAME . '/modules/' . $v . '/views')) {
  19. array_push($paths, ROOT_PATH . '/' . APP_NAME . '/modules/' . $v . '/views');
  20. }
  21. });
  22. $dispatcher->setView(new Twig($paths, isset($config->twig) ? $config->twig->toArray() : []));
  23. }
  24. }
  25. }

Add to application.ini:

  1. [product]
  2. ;app
  3. ;此处填写你的modules,多modules","隔开
  4. application.modules = "Index,Log,Demo"
  5. application.view.ext = twig
  6. ;twig
  7. twig.cache = APP_PATH "../cache"
  8. [devel : product]
  9. ;twig
  10. twig.debug = true

License

MIT license

FOSSA Status