這個問題在這里已經有了答案: 來自 Composer 的 PHP 中未找到例外類 1 個回答 昨天關閉。
我在網上找到了很多 CI3 的解決方案,但沒有一個適用于 CI4。
我使用 composer 安裝了一個包
composer require chillerlan/php-qrcode
然后我添加了一個新的控制器
<?php
namespace App\Controllers;
use App\Controllers\BaseController;
class Qr extends BaseController
{
public function index($path)
{
$data = 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net';
echo '<img src="' . (new QRCode)->render($data) . '" alt="如何在 CodeIgniter 4 中使用 Composer 包?[復制]" />';
}
}
這使我Undefined type 'App\Controllers\QRCode'.的new QRCode。
我需要做什么才能使用 QRCode 類?
uj5u.com熱心網友回復:
試試這個
<?php
namespace App\Controllers;
use App\Controllers\BaseController;
use chillerlan\QRCode\{QROptions, QRCode};
class Qr extends BaseController
{
public function index($path)
{
$data = 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net';
echo '<img src="' . (new QRCode)->render($data) . '" alt="如何在 CodeIgniter 4 中使用 Composer 包?[復制]" />';
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/397973.html
標籤:php 代码点火器 作曲家-php 自动加载 codeigniter-4
