Download the PHP package monken/cli-create without Composer
On this page you can find all versions of the php package monken/cli-create. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download monken/cli-create
More information about monken/cli-create
Files in monken/cli-create
Package cli-create
Short Description Cli-Create is based on CodeIgniter4. It will help you generate template files more quickly when developing projects with CodeIgniter4.
License MIT
Informations about the package cli-create
CodeIgniter4_CLI-Create
Cli-Create is based on CodeIgniter4. It will help you generate template files more quickly when developing projects with CodeIgniter4.
Install
Prerequisites
- CodeIgniter Framework 4.*
- Composer
Composer Install
Use Library
Open Terminal in Mac/Linux or go to Run > “cmd” in Windows and navigate to CodeIgniter4 project’s root:
Now, if you see the following message, the installation is successful.
Guide
create:controller
Create a new controller file.
-
Use
-
Description:
-
Arguments:
- controller_name : The controller name.
- Options:
Create a normal Controller
You can use :
Now, in "app/Controllers" You can see the new Contorller File like this :
Use "-nobase" Option
By default, creating a controller file will extends the BaseController class. If you don't want the default settings, you can use:
The "-nobase" option can be declared after other options.
Now, in "app/Controllers" You can see the new Contorller File like this :
Use "-usemodel" Option
When creating a Controller file, if you need to directly select the Model that will be used, you can use this option.
The "-usemodel" option can be declared after other options.
Now, in "app/Controllers" You can see the new Contorller File like this :
Custom namespace
When creating a Controller file, if you need a custom namespace, you can use the following options:
The "-space" option can be declared after other options.
The namespace in Codeigniter usually maps the actual file storage path, so using this command will automatically create folders according to the value you entered.
Now, in “app/Controllers/System/Admin” You can see the new "-nobase" Controller File like this :
create:controller -rest
Unlike traditional controllers, Codeigniter provides a way to quickly build a RESTFul API. Of course, the CLI-Create library can help you quickly create these files and automatically generate the required settings for you.
-
Use
-
Description:
-
Arguments:
- controller_name : The controller name.
- Options:
Create a normal RESTFul Controller
When you do not need any settings, you can directly execute the following command:
Now, in “app/Controllers” You can see the new RESTFul Controller File like this :
Then, go to "app / Config / Routes.php" and you will see that the routing settings for this Controller have been registered in your configuration file :
Please note that the function of automatically writing to the configuration file is to find the relative position through the comments in the file. Please do not change the comment in the official configuration file, so as not to write the wrong place and cause a program error.
Create RESTFul API with different route name and controller name
You may use this option frequently. Sometimes, our router will not be associated with the location where the Controllers are stored, then it is very suitable to use this option.
The "-d" option allows you to customize the router, and "-space" allows you to customize the controller's namespace. We believe that this requirement needs to be met using these two options, so please use this example to demo.
The “-d” option can be declared after other options.
Now, in “app/Controllers/System/Api” You can see the new RESTFul Controller File like this :
Then, go to "app / Config / Routes.php" and you will see that the routing settings for this Controller have been registered in your configuration file :
Create "WebSafe" RESTFul API
codeigniter allows you to add the "web safe" attribute when setting routes to have it generate update and delete methods that work with HTML forms
The “-w” option can be declared after other options.
Then, go to "app / Config / Routes.php" and you will see the websafe attribute appear in the router's settings.
Create RESTFul API and limit the routes made
You can restrict the routes generated with the option. Only routes that match one of these methods will be created. The rest will be ignored.
The “-o” option can be declared after other options.
Now, in “app/Controllers/System/Api” You can see the new RESTFul Controller File like this :
Then, go to "app / Config / Routes.php" and you will see that the routes you allow to be created are recorded in the router setting :
create:controller -model
Create a new model for use with the new controller.
-
USE
-
Use the options provided by the "create: model" directive.
- The options provided using the "Create: Model" command are not used.
-
-
Description:
- Arguments:
- controller_name : controller name
- controller_options : Options provid by the controller.
- model_options : Options provid by the create:model .If you want to use more than one option, please note that they must be separated by a comma, with "-" removed, and immediately after "=".
- model_name : model name.
- entity_name : entity name.If you use the entity option, you can type this argument.
Create new controller and model
Cli-Create provides a way for you to create a controller and a model at the same time. You can accomplish this with a single line of "spark" command.
Now, open app / Controllers / Blog.php and you should see the new controller file, and the correct model namespace has been written:
Then, open app / Models / BlogModel.php and you will see that the models required by this controller have been created at the same time:
Of course, you can also use all the options provided by "create:controller" when using this command, like this:
Now, open app / Controllers / Notice.php and you should see the new "-nobase" controller file:
Then, open app / Models / NoticeModel.php and you will see that the models required by this controller have been created at the same time:
Use model options
The create:model command provides a variety of different models for you to choose freely. Of course, you can specify some options you want while creating the model and controller.
The options you use must be immediately after "=". You can refer to all the options mentioned in create:model for these options.
Now, open app / Controllers / Blog.php and you should see the new controller file, and the required model has been declared:
Then, open app / Models / BlogModel.php and you will see that the "-basic" model required by this controller has been created at the same time:
Use multiple model options
If you need to use multiple model options at the same time, you only need to separate them with a comma, like this:
This example is more complicated. create new controller, new model and entitiey, and customize the namespace.
Create RESTFul controller and model
You can also create models in "create:controller -rest" at the same time.
This example is more complicated. create new RESTFul controller, new model and entitiey, and customize controller namespace.
create:model
Create a new model file.
-
Use
-
Description:
- Arguments:
- model_name : The model name
- entity_name : The entity name. If you selected -entity option. You can type this arguments.
- Options:
Create a normal model
The model class has a few configuration options that can be set to allow the class’ methods to work seamlessly for you.
You can use :
Now, in "app/Models" You can see the new Model File like this :
Create a basic model
Use Command:
Now, in “app/Models” You can see the new basic Model File like this :
This empty class provides convenient access to the database connection, the Query Builder, and a number of additional convenience methods.
You would replace “group_name” with the name of a defined database group from the database configuration file.
Create a manual model
If you do not need to extend any special class to create a model for your application. All you need is to get an instance of the database connection.
You can use this:
Now, in “app/Models” You can see the new Manual Model File like this :
Create a entity model
CodeIgniter supports Entity classes as a first-class citizen in it’s database layer, while keeping them completely optional to use. They are commonly used as part of the Repository pattern, but can be used directly with the Model if that fits your needs better.
You can use this command :
Now, in “app/Models” You can see the new Manual Model File like this :
And in “app/Entitsies” You can see the new Manual Model File like this :
Custom namespace
When creating a Model FILE, if you need a custom namespace, you can use the following options:
The "-space" option can be declared after other options.
The namespace in Codeigniter usually maps the actual file storage path, so using this command will automatically create folders according to the value you entered.
Now, in “app/Models/Api/System” You can see the new Manual Model File like this :