laravel中引入composer安裝在vendor中的第三方組件

1、安裝第三方組件php

  方法一:使用命令行安裝第三方(已phpword爲例):laravel

composer require phpoffce/phpword ^v0.14.*

  方法二: 修改主項目composer.json文件:json

require": {
        "php": ">=7.1.3",
        "fideloper/proxy": "~4.0",
        "laravel/framework": "5.6.*",
        "laravel/tinker": "~1.0"
    },

  在require中插入須要添加的第三方組件:composer

require": {
        "php": ">=7.1.3",
        "fideloper/proxy": "~4.0",
        "laravel/framework": "5.6.*",
        "laravel/tinker": "~1.0",
        "phpoffice/phpword": "dev-master"
    },

  而後更新composer:ide

composer update

 

2、在項目中使用第三方的組件:ui

  先看看composer引入的phpword在vendor下有個composer.json那裏面有他的命名空間在autoload裏有個PSR路徑spa

"autoload": {
        "psr-4": {
            "PhpOffice\\PhpWord\\": "src/PhpWord"
        }

  而後在相應的項目代碼中引用就行命令行

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\IOFactory; class WordController extends Controller
{
    //
    public function index(){
        $phpword = new PHPWord();
        $section = $phpword->createSection();
    }
}
相關文章
相關標籤/搜索