I find many solutions for CI3 on the web, but none works for CI4.
I installed a package using composer
composer require chillerlan/php-qrcode
Then I added a new Controller
<?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="QR Code" />';
}
}
This gives me Undefined type 'App\Controllers\QRCode'.
for the new QRCode
.
What do I need to do, to use the QRCode class?
Try this
<?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="QR Code" />';
}
}