Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
[CREATE A PACKAGE] - how to do ?
  • Hello guys,
    I have a problem with the package creation. I would like create a package who can add an extend class core.
    In a first time, I would just create a package.
    I follow the tutorial in the FuelPHP's documentation.
    So, I create a directory /djik in packages. I create a file/djik/classes/djik.php with the code :
    <?php
    
    class Djik{
     
     public static function say(){
      echo 'hello';
     }
     
    }
    

    I create a file /djik/bootstrap.php with the follow config :
    <?php
    // Add as core namespace
    Autoloader::add_core_namespace('Djik');
    
    
    Autoloader::add_classes(array(
      'Djik\\Djik' => __DIR__.'/classes/djik.php',
      
    ));
    

    I update the file /app/config/config.php :
    'always_load'  => array(
     'packages'  => array(
      'djik'=> PKGPATH.'djik/',
     ),
    

    When I use the say function (in the action_index() of my Controller), FuelPhp says : ErrorException [ Error ]: Class 'Djik\Djik' not found.
    What is the problem ?
    Thanks for your help Djik
  • You've added it as a core namespace, so you need to use \Djik to access the class.
  • Awesome, it's ok. thanks
  • With the update suggested by Harro all works, but I suggest you to define and use your own namespace for every package: if you will use many packages it will save your life (you can use the same class name for different class in different packages).

Howdy, Stranger!

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

In this Discussion