Skip to content

Latest commit

 

History

History
66 lines (41 loc) · 4.36 KB

overview.md

File metadata and controls

66 lines (41 loc) · 4.36 KB

Sprint Forge

The Forge is a frontend to work with various code generators. While Sprint comes with some basic code generators that you will find handy, you are encouraged to create additional collections of generators that have been customized for your project or specific UI needs.

The code generated by the Forge should be considered a jumping-off point, not the final product. It won't write your application for you. Instead it takes the basic setup of a new module, or creating new migrations, etc from the 1/2 hour or more it might have taken by hand to just a few seconds work.

Using the Forge

The Forge is called from the command line.

$ php sprint forge {generator_name} {parameter_list} -{options}

The {generator_name} must match an existing generator, either in the default collection that Sprint provides, or in one of your own. It must match the name of the folder of the generator.

The {parameter list} is a space separated list of values that the generator expects. This is typically the name of the object that you're creating. For the Model generator it simply expects the name of the model to create.

$ php sprint forge model users

The last elements on your command should be the options. There are a couple of global options that can be used. Other than that, the available options are listed with each generator.

Available Generators

To obtain a list of avialable generators use the forge command by itself.

$ php sprint forge

// Displays something like:
Sprint Collection
controller		controller <name>	Creates a new controller file that extends from BaseController.
scaffold		scaffold <name>		Creates an MVC triad based around a single data type.
model			model <name>		Creates a new model file that extends from CIDbModel.
migration		model <name>		Creates a new migration file.

Click through for a list of provided generators.

Command Help

When you need to get additional help about how to use a command you can type add the option -h or -help after the command name.

$ php sprint forge controller -help

This will print out a long man-page-like description of how to use the command.

Global Options

The following options are available to all generators and can impact the way they work.

module

By default, the generated code will be placed in the standard application locations. You can specify that you want the code generated in a specific module with the -module option. A new module will be created in the first module folder listed in the configuration file if it doesn't already exist.

$ php sprint forge model user -module users

overwrite

None of the generators default to overwriting any files. Instead, those files are simply skipped. If you wish to have the files overwritten during the generation process, you can use the -overwrite option. This will apply to ALL files created during the process. So generators that create many files will overwrite all of them.

$ php sprint forge model user -overwrite

Collections

All generators are stored in groups called collections. A base collection ships with Sprint that includes a number of useful generators for creating models, libraries, even entire modules. However, you might need slightly different variations of the stock generators to better fit your workflow, match specific project needs, or meet company standards. You can do this easily by creating new generators in a new collection.

You should never edit any of the stock generators directly. All your changes would be lost during Sprint upgrades. Instead, create a new folder somewhere on your system. It does not need to be within the application. For many types of generators you would not want to store them per project, but a central location that you could re-use for all of your projects.

Configuration

Next you need to edit the application/config/forge.php config file to let the system know where your template group is stored. You should put your group before the default Sprint group. When the system looks for templates to render, it looks in each folder, in turn, until it locates the file. By putting your group first, it will override the default templates. This also means that you only need to include the specific templates that you want to modify.

$config['forge.collections'] = [
	'personal' => '/full/path/to/new/generators/',
	'sprint'   => MYTHPATH .'_generators/'
];