说明

主要利用composer导入现成的模板视图包

意义

学习其他成熟的框架,了解底层原理

实战

composer命令相关 【可忽略】

composer项目 1+2结构

1.一个目录 :"vendor"
2.两个文件:"composer.json","composer.lock

composer.json

  • 描述了当前项目所以依赖的包/组件/类库和版本
  • json格式
  • 交互式创建 ‘composer init’
[root@VM-0-7-centos work.gzj2001.com]# composer init
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? y

                                            
  Welcome to the Composer config generator  
                                            


This command will guide you through creating your composer.json config.

Package name (<vendor>/<name>) [root/work.gzj2001.com]: gzj2001/test
Description []: gzj2001 blog test
Author [, n to skip]: allen chen <3168680361@qq.com>
Minimum Stability []: 
Package Type (e.g. library, project, metapackage, composer-plugin) []: library
License []: MIT

Define your dependencies.

Would you like to define your dependencies (require) interactively [yes]? no
Would you like to define your dev dependencies (require-dev) interactively [yes]? no

{
    "name": "gzj2001/test",
    "description": "gzj2001 blog test",
    "type": "library",
    "license": "MIT",
    "authors": [
        {
            "name": "allen chen",
            "email": "3168680361@qq.com"
        }
    ],
    "require": {}
}

Do you confirm generation [yes]? yes

image.png

image.png

修改require 以json格式填写

然后 composer install 安装所依赖的包 【不推荐】
composer update //更新json文件

或者直接使用 composer require自动填写composer.json相关依赖

composer install

  • 如果存在composer.lock,就安装这里面要求的包的版本
  • 否则就安装composer.json 中的包,并将安装好的包的版本等信息写入到composer.lock

composer update

  • 主要是检查composer.json是否有更新
  • 如果有 就安装这个包,并将这个包的相关信息写入到composer.lock

composer require

  • 自动创建相关文件并安装
  • 写入

更多composer命令相关可以查看composer中文网
https://docs.phpcomposer.com/

composer包列表网
https://packagist.org/