fuel / parser

Fuel PHP Framework - v1.x template parser package adapters
http://fuelphp.com
64 stars 45 forks source link

Get parser driver instance in controller #19

Closed billmn closed 13 years ago

billmn commented 13 years ago

Look at : http://www.fuelphp.com/forums/topics/view/4059

jschreuder commented 13 years ago

Already possible as @Wanwizard pointed out using the parser method.

Either request it on a specific driver class or on a view object:

View_Smarty::parser();
$view->parser();
billmn commented 13 years ago

No ... if you make a static call in a controller like \Parser\View_Smarty::parser() ( is the same for twig and other drivers ) you haven't execute a View::factory() method and template library class isn't included.

We can add a "include_once" on a _init() function on every driver class, like

public static function _init()
{
    include_once \Config::get('parser.View_Smarty.include');
}
...

I've just prepared all drivers with this method ... if you agree I can send a pull request

jschreuder commented 13 years ago

Adding the inclusion to _init() is a good idea, I would prefer it to still support multiple files even though we know the number of files per driver. That keeps the code nice and consistent:

// Include necessary files
foreach ((array) \Config::get('parser.'.$class.'.include', array()) as $include)
{
    require_once $include;
}
billmn commented 13 years ago

Ok Jelmer! In _init() we also have to add a parent::_init() to not override auto_encode config check.