Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Best way to create modules
  • I am just curious if there is a recommendation for creating modules... I have seen that others have built on it but I am unsure how they got started. I assumed that they had created the module outside of the application then merged it into it. 

  • HarroHarro
    Accepted Answer
    We don't do anything but modules, we only have extended core classes, base classes and generic helper classes in app/classes.

    A module is, from a code point of view, identical to app, it only has a namespace statement at the top of each file. If you're on 1.8/develop, you can have oil generate a module structure.

    I have an empty module ready, that started from a copy of the contents of fuel/app, which all the welcome stuff removed. I just copy that in.
  • Awesome! Thank you.. that's exactly what I was trying to find information about. :)
  • How would you run the command? 

    I tried oil g module posts title:string url_source:string summary:text 

    but it keeps sending me the help screen instead. 
  • Eh, was a bit too hasty, https://github.com/fuel/oil/pull/222

    Ready, but not validated and merged yet. ;-) I'll try to find time for that today.


  • Awesome! I greatly appreciate that. :D
  • Still missing docs, and some corrections to the PR. So I can't merge this functionality yet.
  • Okay then what would you suggest how to generate one?
  • You can always generate as normal, and then move the file from app/classes to the yourmodule/classes folder. All you need to add manually is the namespace statement.

    I personally never generate anything. Once you've made your first controller and you're happy with it, strip it to a generic "skeleton" controller, and re-use that where needed.
  • Alright, I'll try that out. 

    As far as namespace statement goes, I can never seem to get it to work even though if I set the controller prefix in the app/config/config.php file. 

    It seems to work after I change my controllers but it still will not work properly with core classes I believe... 

    Any clarification on this would be great. :)
  • You don't need to change the prefix.

    If in your app a controller is defined as:

    class Controller_Welcome extends Controller {}

    then in a module called Mymodule, it is defined as

    namespace Mymodule;
    class Controller_Welcome extends \Controller {}

    It isn't more complex then that.
  • Alright Thank you. 

    I just saw that https://github.com/fuel/oil/pull/222 has been updated.. I so am looking forward to using this!! Would make my life a lot easier!
  • I saw that you merged it but I am unable to retrieve the update... I think I might be trying to update incorrectly but I am still learning how to use Github. As far as I can tell, I can only pull the updates from the same repository which is fuel/fuel to my moakdesigns/fuel but I don't think I can merge updates from other repositories such as fuel/oil.

    The reason why I say this is that I am still getting the help screen whenever I try running the command line as you have written in the docs.

    $ oil g module blog


  • I downloaded latest oil package from oil repository and pasted everything to fuel/packages/oil that is more than enough to upgrade oil package.

    $ oil g module blog

    Create a blog module inside module directory and a classess folder.

    if u want to create model or controller to blog module all you have to do add --module=blog at the and of oil g controler command.

    $ oil g controller posts --module=blog

    $ oil g model posts post:text --module=blog

  • @MoakDesigns,

    If you installed as a git repo, you need to update your submodules (in the install root: git submodule update).
  • After I downloaded the latest oil package from oil repository and pasted everything, I have this odd uncommitted change that keeps popping up saying Submodule 23834878b(whatever the number is)-dirty and it will not disappear until I removed the new package and put the old one back after I saved the old oil package.  

    I did try the git submodule update and I am not getting any notification on command line about any updates and when I do run the command, all it does is create empty folders, nothing else. So I assume from @kesali you would have to run the extra commands if you want to scaffold anything into the module folder?

    I assume this works just fine with admin scaffold correct?
  • The problem with submodules in general is that they are fixed links to a specific commit hash in the referred-to repository. Which means that if that repo has new commits, you won't see them until the submodule references in fuel/fuel are updated.

    I usually go into the repo folder (in this case fuel/packages/oil), and do a 'git checkout 1.8/develop' to switch to the develop branch, and a 'git pull' to make sure you have the latest code. And forget about these silly submodules...

    See http://fuelphp.com/dev-docs/packages/oil/generate.html#/modules on how to create a new module. After that, you can use the --module switch to generate into that module.
  • Do I do the following:

    $ oil g module users

    $ oil g admin --module=users

    to generate into the users module
  • I would say so. Without having tried it myself...
  • Just tried it and it is scaffolding everything into app/classes instead of app/modules

    jmoakley@WEB221 /c/xampp/htdocs/FuelPHP-Development (module-test)
    $ oil g module users

    jmoakley@WEB221 /c/xampp/htdocs/FuelPHP-Development (module-test)
    $ oil g admin --module=users
            Creating controller: C:\xampp\htdocs\FuelPHP-Development\fuel\app\classes/controller/base.php
            Creating controller: C:\xampp\htdocs\FuelPHP-Development\fuel\app\classes/controller/admin.php
            Creating views: C:\xampp\htdocs\FuelPHP-Development\fuel\app\views/admin/template.php
            Creating views: C:\xampp\htdocs\FuelPHP-Development\fuel\app\views/admin/dashboard.php
            Creating views: C:\xampp\htdocs\FuelPHP-Development\fuel\app\views/admin/login.php
            Creating migration: C:\xampp\htdocs\FuelPHP-Development\fuel\app\modules\users\migrations/001_create_s.php
            Creating model: C:\xampp\htdocs\FuelPHP-Development\fuel\app\classes/model/.php
            Creating controller: C:\xampp\htdocs\FuelPHP-Development\fuel\app\classes/controller/admin\.php
            Creating view: C:\xampp\htdocs\FuelPHP-Development\fuel\app\views/admin\/index.php
            Creating view: C:\xampp\htdocs\FuelPHP-Development\fuel\app\views/admin\/view.php
            Creating view: C:\xampp\htdocs\FuelPHP-Development\fuel\app\views/admin\/create.php
            Creating view: C:\xampp\htdocs\FuelPHP-Development\fuel\app\views/admin\/edit.php
            Creating view: C:\xampp\htdocs\FuelPHP-Development\fuel\app\views/admin\/_form.php
            Creating view: C:\xampp\htdocs\FuelPHP-Development\fuel\app\views/template.php

  • MoakDesigns, I did not implemented the --module for "oil g admin", only for other generating tasks. If there's need for it you're always welcome to make a PR ;)
  • Ahh.... ;-)
  • @philipptempel That explains why it wouldn't work the way I was hoping it would. 

    How have you been generating modules then? Same as @Harro has mentioned before... move the classes into the modules folders respectively? 
  • @MoakDesigns, you can create modules using "oil generate module <name>" as the docs state. Then, every generate argument (except for "admin") takes the --module option (but beware of "oil g config", there's already been a --module option which I haven't altered the behavior of).
    Using the --module=<name> all generated files i.e., migrations, models, will be put into the module's respective folder.

    At least it worked for me and my tests. If something's not working properly, feel free to ask or nag about it ;) using the forums, the IRC channel, or github (here's the forked repo I used to create the PR https://github.com/philipptempel/fuel-oil/tree/patch/module_support)
  • Well, I am unaware of the available --module option and can't find any docs about that. Can you point me in the correct direction?
  • The --module option is a simple switch for the command line to "pipe" all output i.e., files created like models, migrations, controller, ..., to be created within the directory of the module and not within APPPATH.
    You can use it easily via e.g. ```$ php oil generate model --module=blog post body:mediumtext```

Howdy, Stranger!

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

In this Discussion