Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Modules usage..
  • This is my first post as FuelPHP user, and I have one question about usage of modules.
    I have created a class Utils into directory app\modules\utils\utils.app
    I change my config.php into app\config\config,php including the follow declaration:

        'module_paths' => array(
                APPPATH.'modules'.DS
            ),

    and

        'always_load'  => array(
            'modules'  => array(
                'utils',
            ),

    at this moment my execution dont  have any trouble, but if I call any method from Utils I have the follow error:

    ErrorException [ Error ]: Class 'Utils' not found

    My class start as it:
    <?php
        namespace Utils;
       
        class Utils {
           public static function method1() { ... }
           public static function method2() { ... }
           public static function method3() { ... }
        }

    Whats happening??? How can I use modules in Fuel???
    Thanks for any sugestion....



    Medeiros
  • HarroHarro
    Accepted Answer
    All classes should go into the "classes" folder. A module needs to have the same structure as your app folder, with "classes", "classes/controller", etc...
  • I have another question: my class don't extends any other  (controller, model or view) is a new class. If I create a directory as model/classes/controller or model/classes/model/ or model/classes/view I need extends this classes (controller, model or view)???
  • HarroHarro
    Accepted Answer
    Classes go into the 'classes' folder, following the "cascading file system".

    A location of a file is determined as follows:
    - take the namespace and the classname, and concatenate them using a slash as separator
    - replace all slashes, backslashes, and underscores to DIRECTORY_SEPARATOR
    - append '.php'.

    so, if your class is called "Controller_Test" in the global namespace, it would be in "classes/controller/test.php". If the class is called "User_Meta" in the namespace "Model", it would be in "classes/model/user/meta.php". If the class is called "Test" in the global namespace, it would be in "classes/test.php".

    You can deviate from these rules by telling the autoloader where to find a namepace. This is used by Modules and Packages, to map their namespace to their 'classes' folder. This is usually done in a bootstrap file (for modules, it's build into the Router and Module class).

Howdy, Stranger!

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

In this Discussion