首页 > 解决方案 > 在 Laravel 5 之外使用 Facade(在 CodeIgniter 中)

问题描述

我正在尝试让 Laravel 包(maatwebsite/excel)在 CodeIgniter 上工作。
我得到的错误是:Message: A facade root has not been set.

有没有办法让 Laravel 外观在 CodeIgniter 下工作?

我读了这篇文章:https ://www.sitepoint.com/how-laravel-facades-work-and-how-to-use-them-elsewhere/这表明我需要打电话

Illuminate\Support\Facade::setFacadeApplication($app);

但应该$app是什么?

到目前为止,我的代码是这样的:

// Report.php
class Rapportage extends MY_Controller {
    public function __construct()
    {
        parent::__construct();

        // This doesn't work, what should I put here?
        Illumiante\Support\Facade::setFacadeApplication($app);
    }

    public function generate_rapport()
    {
        // This is where the error occurs
        return Excel::download(new PersonExport, 'rapport.xlsx');
    }
}

// Reports/Persons.php
namespace Exports;

use Person;
use Maatwebsite\Excel\Concerns\FromCollection;

class PersonExport implements FromCollection
{
    public function collection()
    {
        return Person::all();
    }
}

标签: phplaravelcodeignitermaatwebsite-excel

解决方案


推荐阅读