<aclass="btn btn-neutral float-right"href="https://github.com/codeigniter4/CodeIgniter4/edit/develop/user_guide_src/source/cli/cli_generators.rst">Edit this page</a>
<p>All built-in generators reside under the <codeclass="docutils literal notranslate"><spanclass="pre">Generators</span></code> group when listed using <codeclass="docutils literal notranslate"><spanclass="pre">php</span><spanclass="pre">spark</span><spanclass="pre">list</span></code>.
<p>where <codeclass="docutils literal notranslate"><spanclass="pre"><generator_command></span></code> will be replaced with the command to check.</p>
<p>Do you need to have the generated code in a subfolder? Let’s say if you want to create a controller
class to reside in the <codeclass="docutils literal notranslate"><spanclass="pre">Admin</span></code> subfolder of the main <codeclass="docutils literal notranslate"><spanclass="pre">Controllers</span></code> folder, you will just need
to prepend the subfolder to the class name, like this: <codeclass="docutils literal notranslate"><spanclass="pre">php</span><spanclass="pre">spark</span><spanclass="pre">make:controller</span><spanclass="pre">admin/login</span></code>. This
command will create the <codeclass="docutils literal notranslate"><spanclass="pre">Login</span></code> controller in the <codeclass="docutils literal notranslate"><spanclass="pre">Controllers/Admin</span></code> subfolder with
a namespace of <codeclass="docutils literal notranslate"><spanclass="pre">App\Controllers\Admin</span></code>.</p>
</div>
<divclass="admonition note">
<pclass="admonition-title">Note</p>
<p>Working on modules? Code generation will set the root namespace to a default of <codeclass="docutils literal notranslate"><spanclass="pre">APP_NAMESPACE</span></code>.
Should you need to have the generated code elsewhere in your module namespace, make sure to set
the <codeclass="docutils literal notranslate"><spanclass="pre">--namespace</span></code> option in your command, e.g., <codeclass="docutils literal notranslate"><spanclass="pre">php</span><spanclass="pre">spark</span><spanclass="pre">make:model</span><spanclass="pre">blog</span><spanclass="pre">--namespace</span><spanclass="pre">Acme\\Blog</span></code>.</p>
<p>Make sure when setting the <codeclass="docutils literal notranslate"><spanclass="pre">--namespace</span></code> option that the supplied namespace is a valid
namespace defined in your <codeclass="docutils literal notranslate"><spanclass="pre">$psr4</span></code> array in <codeclass="docutils literal notranslate"><spanclass="pre">Config\Autoload</span></code> or defined in your composer autoload
file. Otherwise, code generation will be interrupted.</p>
<p>Since v4.0.5, use of <codeclass="docutils literal notranslate"><spanclass="pre">migrate:create</span></code> to create migration files has been deprecated. It will be removed in
future releases. Please use <codeclass="docutils literal notranslate"><spanclass="pre">make:migration</span></code> as replacement. Also, please use <codeclass="docutils literal notranslate"><spanclass="pre">make:migration</span><spanclass="pre">--session</span></code>
to use instead of the deprecated <codeclass="docutils literal notranslate"><spanclass="pre">session:migration</span></code>.</p>
<h2><aclass="toc-backref"href="#id29">Built-in Generators</a><aclass="headerlink"href="#built-in-generators"title="Permalink to this headline"></a></h2>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--namespace</span></code>: Set the root namespace. Defaults to value of <codeclass="docutils literal notranslate"><spanclass="pre">APP_NAMESPACE</span></code>.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--suffix</span></code>: Append the component suffix to the generated class name.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--force</span></code>: Set this flag to overwrite existing files on destination.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">name</span></code>: The name of the command class. <strong>[REQUIRED]</strong></p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--command</span></code>: The command name to run in spark. Defaults to <codeclass="docutils literal notranslate"><spanclass="pre">command:name</span></code>.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--group</span></code>: The group/namespace of the command. Defaults to <codeclass="docutils literal notranslate"><spanclass="pre">CodeIgniter</span></code> for basic commands, and <codeclass="docutils literal notranslate"><spanclass="pre">Generators</span></code> for generator commands.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--type</span></code>: The type of command, whether a <codeclass="docutils literal notranslate"><spanclass="pre">basic</span></code> command or a <codeclass="docutils literal notranslate"><spanclass="pre">generator</span></code> command. Defaults to <codeclass="docutils literal notranslate"><spanclass="pre">basic</span></code>.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--namespace</span></code>: Set the root namespace. Defaults to value of <codeclass="docutils literal notranslate"><spanclass="pre">APP_NAMESPACE</span></code>.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--suffix</span></code>: Append the component suffix to the generated class name.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--force</span></code>: Set this flag to overwrite existing files on destination.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">name</span></code>: The name of the config class. <strong>[REQUIRED]</strong></p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--namespace</span></code>: Set the root namespace. Defaults to value of <codeclass="docutils literal notranslate"><spanclass="pre">APP_NAMESPACE</span></code>.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--suffix</span></code>: Append the component suffix to the generated class name.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--force</span></code>: Set this flag to overwrite existing files on destination.</p></li>
</ul>
</section>
</section>
<sectionid="make-controller">
<h3><aclass="toc-backref"href="#id33">make:controller</a><aclass="headerlink"href="#make-controller"title="Permalink to this headline"></a></h3>
<p>Creates a new controller file.</p>
<sectionid="id7">
<h4>Usage:<aclass="headerlink"href="#id7"title="Permalink to this headline"></a></h4>
<h4>Argument:<aclass="headerlink"href="#id8"title="Permalink to this headline"></a></h4>
<ulclass="simple">
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">name</span></code>: The name of the controller class. <strong>[REQUIRED]</strong></p></li>
</ul>
</section>
<sectionid="id9">
<h4>Options:<aclass="headerlink"href="#id9"title="Permalink to this headline"></a></h4>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--bare</span></code>: Extends from <codeclass="docutils literal notranslate"><spanclass="pre">CodeIgniter\Controller</span></code> instead of <codeclass="docutils literal notranslate"><spanclass="pre">BaseController</span></code>.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--restful</span></code>: Extends from a RESTful resource. Choices are <codeclass="docutils literal notranslate"><spanclass="pre">controller</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">presenter</span></code>. Defaults to <codeclass="docutils literal notranslate"><spanclass="pre">controller</span></code>.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--namespace</span></code>: Set the root namespace. Defaults to value of <codeclass="docutils literal notranslate"><spanclass="pre">APP_NAMESPACE</span></code>.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--suffix</span></code>: Append the component suffix to the generated class name.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--force</span></code>: Set this flag to overwrite existing files on destination.</p></li>
<p>If you use <codeclass="docutils literal notranslate"><spanclass="pre">--suffix</span></code>, the generated controller name will be like
<codeclass="docutils literal notranslate"><spanclass="pre">ProductController</span></code>. That violates the Controller naming convention
when using <aclass="reference internal"href="../incoming/controllers.html#controller-auto-routing-improved"><spanclass="std std-ref">Auto Routing</span></a>
(Controller class names MUST start with an uppercase letter and
ONLY the first character can be uppercase). So <codeclass="docutils literal notranslate"><spanclass="pre">--suffix</span></code> can be used
when you use <aclass="reference internal"href="../incoming/routing.html#defined-route-routing"><spanclass="std std-ref">Defined Routes</span></a>.</p>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">name</span></code>: The name of the entity class. <strong>[REQUIRED]</strong></p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--namespace</span></code>: Set the root namespace. Defaults to value of <codeclass="docutils literal notranslate"><spanclass="pre">APP_NAMESPACE</span></code>.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--suffix</span></code>: Append the component suffix to the generated class name.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--force</span></code>: Set this flag to overwrite existing files on destination.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">name</span></code>: The name of the filter class. <strong>[REQUIRED]</strong></p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--namespace</span></code>: Set the root namespace. Defaults to value of <codeclass="docutils literal notranslate"><spanclass="pre">APP_NAMESPACE</span></code>.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--suffix</span></code>: Append the component suffix to the generated class name.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--force</span></code>: Set this flag to overwrite existing files on destination.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">name</span></code>: The name of the model class. <strong>[REQUIRED]</strong></p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--dbgroup</span></code>: Database group to use. Defaults to <codeclass="docutils literal notranslate"><spanclass="pre">default</span></code>.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--return</span></code>: Set the return type from <codeclass="docutils literal notranslate"><spanclass="pre">array</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">object</span></code>, or <codeclass="docutils literal notranslate"><spanclass="pre">entity</span></code>. Defaults to <codeclass="docutils literal notranslate"><spanclass="pre">array</span></code>.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--table</span></code>: Supply a different table name. Defaults to the pluralized class name.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--namespace</span></code>: Set the root namespace. Defaults to value of <codeclass="docutils literal notranslate"><spanclass="pre">APP_NAMESPACE</span></code>.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--suffix</span></code>: Append the component suffix to the generated class name.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--force</span></code>: Set this flag to overwrite existing files on destination.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">name</span></code>: The name of the seeder class. <strong>[REQUIRED]</strong></p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--namespace</span></code>: Set the root namespace. Defaults to value of <codeclass="docutils literal notranslate"><spanclass="pre">APP_NAMESPACE</span></code>.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--suffix</span></code>: Append the component suffix to the generated class name.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--force</span></code>: Set this flag to overwrite existing files on destination.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">name</span></code>: The name of the migration class. <strong>[REQUIRED]</strong></p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--session</span></code>: Generate a migration file for database sessions.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--table</span></code>: Set the table name to use for database sessions. Defaults to <codeclass="docutils literal notranslate"><spanclass="pre">ci_sessions</span></code>.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--dbgroup</span></code>: Set the database group for database sessions. Defaults to <codeclass="docutils literal notranslate"><spanclass="pre">default</span></code> group.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--namespace</span></code>: Set the root namespace. Defaults to value of <codeclass="docutils literal notranslate"><spanclass="pre">APP_NAMESPACE</span></code>.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--suffix</span></code>: Append the component suffix to the generated class name.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--force</span></code>: Set this flag to overwrite existing files on destination.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">name</span></code>: The name of the validation class. <strong>[REQUIRED]</strong></p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--namespace</span></code>: Set the root namespace. Defaults to value of <codeclass="docutils literal notranslate"><spanclass="pre">APP_NAMESPACE</span></code>.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--suffix</span></code>: Append the component suffix to the generated class name.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">--force</span></code>: Set this flag to overwrite existing files on destination.</p></li>
<h2><aclass="toc-backref"href="#id40">Scaffolding a Complete Set of Stock Code</a><aclass="headerlink"href="#scaffolding-a-complete-set-of-stock-code"title="Permalink to this headline"></a></h2>
<p>Sometimes in our development phase we are creating functionalities by groups, such as creating an <em>Admin</em> group.
This group will contain its own controller, model, migration files, or even entities. You may be tempted to type
each generator command one-by-one in the terminal and wishfully thinking it would be great to have a single generator
command to rule them all.</p>
<p>Fret no more! CodeIgniter4 is also shipped with a dedicated <codeclass="docutils literal notranslate"><spanclass="pre">make:scaffold</span></code> command that is basically a
wrapper to the controller, model, entity, migration, and seeder generator commands. All you need is the class
name that will be used to name all the generated classes. Also, <strong>individual options</strong> supported by each
<p>To include an <codeclass="docutils literal notranslate"><spanclass="pre">Entity</span></code> class in the scaffolded files, just include the <codeclass="docutils literal notranslate"><spanclass="pre">--return</span><spanclass="pre">entity</span></code> to the command
<p>All generator commands must use the <codeclass="docutils literal notranslate"><spanclass="pre">GeneratorTrait</span></code> to fully utilize its methods that are used in code