or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing
xxxxxxxxxx
CodeIgniter4_CLI-Create
Cli-Create is based on CodeIgniter4. It will help you generate template files more quickly when developing projects with CodeIgniter4.
中文使用說明
Guide
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Install
Prerequisites
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:
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.
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:
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 :
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
Description:
Arguments:
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.
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:
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.
Now, in “app/Models/Api/System” You can see the new Manual Model File like this :