2017 © Pedro Peláez
 

library yaf-twig-adapter

image

justmd5/yaf-twig-adapter

  • Monday, May 16, 2016
  • by justmd5
  • Repository
  • 1 Watchers
  • 3 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

yaf-twig-adapter

FOSSA Status, (*1)

Twig Adapter for Yaf PHP Framework with namespace enabled., (*2)

Installation

You can install via Composer., (*3)

At first create composer.json file:, (*4)

{
    "require": {
        "justmd5/yaf-twig-adapter":">=1.0"
    }
}

Run composer to install., (*5)

$ composer install

Finally, include vendor/autoload.php at index.php, (*6)

require_once 'vendor/autoload.php';

Add to Bootstrap.php:, (*7)

<?php

use \Yaf\Bootstrap_Abstract;
use \Yaf\Dispatcher;
use \Yaf\Application;
use \JustMd5\TwigAdapter;

class Bootstrap extends Bootstrap_Abstract
{

    /**
     * @param Dispatcher $dispatcher
     */
    protected function _initTwig(Dispatcher $dispatcher)
    {
        $config = Application::app()->getConfig();
        $dispatcher->setView(new Twig(APP_PATH.'views', $config->twig->toArray()));
    }
}

Add to application.ini:, (*8)

[product]

;app
application.view.ext = twig

;twig
twig.cache = APP_PATH "../cache"

[devel : product]

;twig
twig.debug = true

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

<?php

use \Yaf\Bootstrap_Abstract;
use \Yaf\Dispatcher;
use \Yaf\Application;
use \JustMd5\TwigAdapter;

class Bootstrap extends Bootstrap_Abstract
{

    /**
     * @param Dispatcher $dispatcher
     */
      public function _initTwig(Dispatcher $dispatcher)
        {
            if (REQUEST_METHOD !== 'CLI') {
                $config = Application::app()->getConfig();
                $modules_names = explode(',', $config->application->modules);
                $paths = [ROOT_PATH . '/' . APP_NAME . '/views'];
                array_walk($modules_names, function ($v) use (&$paths) {
                    if (is_dir(ROOT_PATH . '/' . APP_NAME . '/modules/' . $v . '/views')) {
                        array_push($paths, ROOT_PATH . '/' . APP_NAME . '/modules/' . $v . '/views');
                    }
                });
                $dispatcher->setView(new Twig($paths, isset($config->twig) ? $config->twig->toArray() : []));
            }

        }
}

Add to application.ini:, (*9)

[product]

;app
;此处填写你的modules,多modules","隔开
application.modules = "Index,Log,Demo"
application.view.ext = twig

;twig
twig.cache = APP_PATH "../cache"
[devel : product]
;twig
twig.debug = true

License

MIT license, (*10)

FOSSA Status, (*11)

The Versions

16/05 2016

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

by Avatar justmd5

yet another framework twig for yaf twig for yet another framework yar集成twig

25/04 2016

1.0

1.0.0.0

  Sources   Download

MIT

The Requires

 

by Avatar justmd5

yet another framework twig for yaf twig for yet another framework yar集成twig