QrCode Helper

What is the QrCode Helper?

This helper allows you to easily create and render Qr Codes in your Yii 2 applications.


The preferred way to install this extension is through composer.

Either run

composer require 2amigos/yii2-qrcode-helper:~1.0

or add the following to the require section of your application's composer.json file:

"2amigos/2amigos/yii2-qrcode-helper" : "~1.0" 

Usage example

The helper comes with some format helper classes that will help you to create the different type of QrCodes that a mobile phone scanner will understand.

The library comes with the following formats:

  • Bitcoin
  • BookMark
  • Geo
  • iCal
  • MailMessage
  • MailTo
  • MeCard
  • MMS
  • Phone
  • Sms
  • vCard
  • Wifi
  • Youtube

To render the qrcode, add this to your HTML page:

<img src="<?= Url::to(['route/qrcode'])?>" />

The route/qrcode is a demo name action to the controller's action that will render the QrCode. Here is our action qrcode in the RouteController code:

use doamigos\qrcode\formats\MailTo;
use dosamigos\qrcode\QrCode;

\\ [...]

public function actionQrcode() {
    // For the sake of the example, we are using a MailToFormat. 
    $mailTo = new MailTo(['email' => 'email@example.com']);
    return QrCode::png($mailTo->getText());

\\ [...]

Share this

Contributors Thanks All


Do you have a good idea? Why Don't We Talk?