Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
My namespace and classes structure
  • Hi guys,
    I'm trying to develop an app with fuel, but I have some questione about namespace and classes. This is my structure in the "app" folder: - classes
    --- controller
    --- model
    --- utility
    tag
    permission I have some problem using "Tag" and "Permission" (in a static way, of course), because if I use "Utility_Tag::something()" it works, but I want to use it with only "Tag::something()" or, better, "Namespace\Tag::something()". How can I do that?
  • If you want to use "Namespace\Tag::something()" have you tried to create a module?
    modules
      - utilty
        - classes
          - tag.php
          - permission.php
    

    Tag.php
    namespace Utility;
    
    class Tag {
      ...
    }
    

    Autoload ( or load manually ) module in your config.php ( using "always_load" array )
    And now you can use \Utility\Tag::something();
  • Mmm I didn't thought about it... A simple explanation:
    - Module are part of my application
    - Package are generics pieces of code that I can reuse, right? If what I written was right, thank you! I thought that I have to put them in classes folder because are a part of this application :-P
  • Mmm I tried to do what you suggested, but there was an error... "Trying to add a non-existent module 'utility' ".
    My folder structure is: modules
    --- utility
    classe
    permission
    tag Classes have namespace e definition like you write and I call them with \Utility\Permission::method() What is the problem?
  • Have you configured the modules directory in your app/config/config.php?
  • It seems that what you want to create is a package... Modules are used as application extensions... like a blog, forum or faq that you can make portable and use on multiple sites. Packages are core extensions. That is, they are used to extend the framework itself, not the application. Besides, if you wanted to be able to call a module file, I believe you would first have to use
    \Fuel::add_module('utility');
    

    I believe.
  • That is correct. Otherwise the mapping between the namespace and the module isn't known to the autoloader.
  • Thank you, now finally works... I created a package (thanks nerdsrescueme) and everything works well... And I've understand the differenze between modules and packages. I hope to release the new application as soon as possible! :-)

Howdy, Stranger!

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

In this Discussion