Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to set always_load config of Module inside config.php and call that from parser Twig.
  • I have problem when I set autoload file config of module inside config.php.

    my module

    themes
    ----- classes
    ---------- controller
    --------------- themes.php
    ----- config
    ----------- themes.php

    my themes.php is

    <?php

    namespace Themes;

    return array(
        'test'        => 'hola',
    );

    then I am try to set always_load in config.php 

    'config'  => array(
                         'themes::themes',
                     ),


    and then in my twig template custom is 

    <?php

    class Twig_Fuel_Extension extends \Parser\Twig_Fuel_Extension
    {

    public function getFunctions()
    {
    return array_merge(parent::getFunctions(), array(
                    'config_get'   => new Twig_Function_Function('\Config::get'),     //adding by viyancs
                    ));
    }

    look that I have config_get function and will be usage in twig view template like this

    {{config_get('themes.test')}} //it's should be show hola

    but I am not still get that value, I think twig looking up config under global path , not in module path.

    any suggestion ? sorry for my english
  • Config files don't have a namespace.

    If you don't specify a config group, the configuration will be loaded into a group with the same name as the file. Which in this case is "themes::themes", not "themes".

    If you want to load the config file into the "themes" group, use:

    'config'  => array(
        'themes::themes' => 'themes',
    ),

    And the parser's Twig extension class already contains an entry to access config items, called 'config'. So no need to define your own extension.
  • I am still not get the point, it's possible load module config in the config.php global file ?
  • Yes, why not? You already did it.

    The question is, where is it loaded into? This is called the 'config group', which basically is the first part of the config key.

    If you don't specify a group name (like you did) in always_load, it will be loaded into the group with the same name as the config file. This can be compared to Config::load('themes', true);

    So in your original load:

    'config'  => array(
        'themes::themes',
    ),

    You need to use

    Config::get('themes::themes.test')

    Since you didn't specify a group name (so the group name equals the config file name). If you change your always_load to what I suggested

    'config'  => array(
        'themes::themes' => 'themes',
    ),

    You can use

    Config::get('themes.test')

    like you want to...

    p.s. if so specify something that doesn't exist, you'll get a "file not found" ConfigException.
  • Thanks for your advance. I am still not get that value by 

    'config'  => array(
        'themes::themes' => 'themes',
    ),

    and call with Config::get('themes.test')

    I want to load Config inside Module Themes

    themes
    ----- classes
    ---------- controller
    --------------- themes.php
    ----- config
    ----------- themes.php

    autoload and I can access with global . when I try to debug that with var_dump(\Config::get('themes')); that just return empty array.
  • Is the module loaded? If not, it's not accessable.
  • Hey You right, thanks for helping, I am forget this 

    'modules'  => array(
                         'themes'
                     ),


Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion