QrCodesController.php 705 Bytes
<?php
namespace App\Controller;

use App\Controller\AppController;
use \PHPQRCode\QRcode;

class QrCodesController extends AppController
{
	
	public function creer($message = null) {
		
			$fileName = $this->request->session()->id().'.png';
			$cakephpPath = str_replace('webroot/index.php', '', $_SERVER['SCRIPT_FILENAME']);
			$qrCodePath = $cakephpPath . 'webroot/img/qrcodes/' . $fileName;
			
			$this->request->session()->write('filename', $fileName);
			$this->request->session()->write('qrCodePath', $qrCodePath);
			
			if($message == null) {
				return QRcode::png($this->request->session()->read('qrUrl'), $qrCodePath);
			} else {
				return QRcode::png($message, $qrCodePath);
			}
			
	}
	
}