laravel中引入composer安装在vendor中的第三方组件

一、安装第三方组件

  方法一:使用命令行安装第三方(已phpword为例):

composer require phpoffce/phpword ^v0.14.*

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

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

  在require中插入需要添加的第三方组件:

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

  然后更新composer:

composer update

 

二、在项目中使用第三方的组件:

  先看看composer引入的phpword在vendor下有个composer.json那里面有他的命名空间在autoload里有个PSR路径

"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();
    }
}

 

转载于:https://www.cnblogs.com/michealLang/p/8747228.html

你可能感兴趣的:(laravel中引入composer安装在vendor中的第三方组件)