An example of Yii2.0 realizing the function of generating two dimensional code

  • 2021-08-10 07:13:05
  • OfStack

In this paper, an example is given to show that Yii 2.0 realizes the function of generating 2-dimensional code. Share it for your reference, as follows:

Install via composer:

1. The following method is loaded via composer


php composer.phar require "2amigos/yii2-qrcode-helper" "*"

Or add


"2amigos/yii2-qrcode-helper" : "*"

To the corresponding project's composer. json file

Install via archive:

Users who are not used to using composer can click here to download 2D code extension.

Then unzip and change the file name to yii2-qrcode-helper and put it under the directory vendor/2amigos/

Edit/vendor/yiisoft/extensions. php and add the following code to the array


'2amigos/yii2-qrcode-helper' => 
   array (
    'name' => '2amigos/yii2-qrcode-helper',
    'version' => '1.0.2.0',
    'alias' => 
    array (
     '@dosamigos/qrcode' => $vendorDir . '/2amigos/yii2-qrcode-helper/src',
    ),
 ),

Usage

Add 1 code to your controller


use dosamigos\qrcode\QrCode;  // Introducing class 
\\ ... 
public function actionQrcode() 
{ 
  return QrCode::png('http://www.yii-china.com');  // Call 2 Dimension code generation method 
}
public function actionDemo()
{
  return $this->render('index');
}

Add the following code to your page (demo/index)


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

Visit the method demo, and you can see a beautiful 2-dimensional code

PS: Here we recommend another 2D code online generation tool for your reference:

Online 2-D code generation tool (enhanced version)
http://tools.ofstack.com/transcoding/jb51qrcode

More readers interested in Yii can check the topics of this site: "Introduction to Yii Framework and Summary of Common Skills", "Summary of Excellent Development Framework of php", "Basic Tutorial for Introduction to smarty Template", "Introduction to php Object-Oriented Programming", "Summary of Usage of php String (string)", "Introduction to php+mysql Database Operation" and "Summary of Common Database Operation Skills of php"

Hope that this article is based on the framework of Yii PHP programming help.


Related articles: