Generate
FUEL CMS provides a command line tool to help you auto generate starter files for your simple and advanced modules. To do so, navigate to the folder (e.g. using "cd") where the main bootstrap index.php file exists. Then you can type the commands below which use the CodeIgniter CLI to generate files automatically.
Configuration and Templates
The default generated template files exist in the fuel/modules/fuel/views/_generated/{type} folder where {type} is either "advanced", "model" or "simple". You can overwrite these defaults by creating a fuel/application/views/_generated/{type} folder with files that correspond to the files specified in the FUEL configuration file under the "generated" parameter. Additionally, you can set additional module folders to look in by adding to the "search" parameter array shown in the configuration array below:
$config['generate'] = array( 'search' => array('app', 'fuel'), 'advanced' => array( 'assets/css/{module}.css', 'assets/images/ico_cog.png', 'assets/js/{ModuleName}Controller.js', 'assets/cache/', 'config/{module}.php', 'config/{module}_constants.php', 'config/{module}_routes.php', 'controllers/{module}_module.php', 'helpers/{module}_helper.php', 'install/install.php', 'libraries/Fuel_{module}.php', 'language/english/{module}_lang.php', 'models/', 'tests/sql/', 'views/_admin/{module}.php', 'views/_blocks/', 'views/_docs/index.php', 'views/_layouts/', ), 'simple' => 'MY_fuel_modules.php', 'model' => array( '{model}_model.php', 'sql/{table}.sql', ), );
Models
The following will create a model named "examples_model.php", generate a placeholder table (you'll need to modify):
php index.php fuel/generate/model examples // generates multiple models at once php index.php fuel/generate/model examples:examples2 // generates a model in an advanced module named examples php index.php fuel/generate/model my_model examples
If you are on a MAC and having trouble where the script is outputting nothing, you may need to make sure you are calling the right php binary. In my case, I needed to call to a /Applications/MAMP/bin/php5/bin/php. Here is a thread that talks about it more: https://forum.codeigniter.com/thread-23025.html Hopefully it saves you some time too!
Separating module names with a colon will generate multiple models.
Simple Modules
The following will create a model named "examples_model.php", generate a placeholder table (you'll need to modify), add the permissions to manage it in the CMS, and will add it to the fuel/application/config/MY_fuel_modules.php:
php index.php fuel/generate/simple examples
Advanced Modules
The following will create a directory named "test" in the fuel/modules/ folder, as well as create a permission and add it to the "modules_allowed" FUEL configuration. It will generate by default the files specified in the FUEL configuration file under the generated parameter:
php index.php fuel/generate/advanced examples
After creating the advanced module, you will need to still setup your simple modules within that advanced module. To do that, you can pass a second parameter to the "simple" generate CLI command to tell which advanced module folder to generate the simple module:
php index.php fuel/generate/simple my_model examples
Placeholder Variables
The following variables are available to be used in your generation templates:
- {module}: the module name (lowercased)
- {Module}: the module name (ucfirst)
- {model}: the model name without the "_model" suffix (lowercased)
- {table}: the table name
- {module_name}: the name of the module with the first letter of each word upper cased (e.g. My Module)
- {Model_name}: the model name with the first letter upper cased and without the suffix (e.g. News)
- {model_record}: The model records name which will remove any pluralization
- {ModuleName}: A camel-cased version of the module name
- {MODULE_NAME}: An all upper cased version of the module's name (used for constants)
Samples
By default, the FUEL generate command comes with several models that we thought were pretty common to many website projects and so we included them as samples—they are news, events, careers. When creating a model or simple module with those names, you will get those models generated instead as a starting point.