I have used Laravel before, and the artisan command that comes with the framework is very cool. Now work needs, to learn FuelPHP, first see the framework directory structure, there is a coposer.json framework that can be managed with composer, and must also have its own command tool.
For beginners, you might as well use commands to automatically generate files, and then look at these generated files to understand basic CRUD operations.
1. Preparation
1. To use the oil command, you need to install composer first
See the official website to install by yourself https://getcomposer.org/download/
2. Connect and create the database correctly
Database configuration in /fuel/app/config/development/db.php
Below is the /fuel/app/ directory structure
3. Open the command editing tool and switch to the framework root directory.
2. Even if there is no local server, you can access the advanced command server of the website
php oil server
Now you can visit http://localhost:8000, but this state needs to be maintained (another window is opened to execute the other commands below). Ctrl-C to quit.
3. The most common commands to create MVC and other required files generate
First look at what files can be created, g is the abbreviation of generate.
php oil g help
1. Scaffold, as the name suggests, can create a series of MVCs with one command. Simple CRUD operations, only one command is required, no need to write any code by yourself.
Example: Create an MVC series file of article, with four fields of title, content, author, and reading.
php oil g scaffold article title:varchar content:text author:varchar reading:int
So many files have been generated, including controller, model, view, and migration files. You can see the specific additions, deletions, and changes to the code. (Because the table has not yet been generated, the data cannot be imported, continue to look down.)
2、controller
Example: There are four methods to create ccontroller category, index, store, update, delete
php oil g controller category index store update delete
Generate a controller file and four view files corresponding to the method.
3、model
Example: Create a model category with a name field
php oil g model category name:varchar
Generate model and database-related migration files
Note: If migration is not required, add parameters later
php oil g model tag name:varchar --no-migration
If soft delete is required, model_soft is required
php oil g model post title:varchar[50] user_id:int --soft-delete
4、presenter
php oil g controller post action1 action2 --with-presenter
5、migration
♦ Perform file migration and automatically create tables from migration files
php oil refine migrate
The database will have a table called migration, which records the files to be migrated.
♦ Generate migration files, or operate on tables, in short, the file name should be as the name suggests.
php oil generate migration create_users name:text email:string[50] password:string[125] // 创建 users 表 php oil generate migration rename_table_users_to_accounts // 修改 users 表名为 accounts php oil generate migration add_bio_to_accounts bio:text // 添加字段 bio php oil generate migration delete_bio_from_accounts bio:text // 删除字段 bio php oil generate migration rename_field_name_to_username_in_accounts // 修改字段名 php oil generate migration drop_accounts
6、task
php oil g task newtask cmd1 cmd2
7、config
♦ php oil g config test hello:world generates a common configuration file test.php
♦ php oil g config package 生成 package.php
♦ php oil g config form --overwrite rewrites the configuration files in the core/config/ directory.
8、module
php oil g module blog will have an additional blog directory in the framework root directory.
4. Simple command refine to perform some tasks
Also help look at the executable tasks
php oil refine help
You can try the commands in the red box above, there are some very interesting effects
Five, the command package to install or uninstall the package file
Package file resources are managed in the configuration file package.php
php oil package install test-package install test-package package
php oil package uninstall test-package uninstall package file
6. It is convenient to execute the shortcut command console of php at any time
The php oil console will enter the PHP environment and write php code at will
Seven, the command test that can be unit tested
It is used for unit test, and will be added after it is used.