Yii2.0-生成二维码实例

composer安装

1.composer下载:

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

归档安装

1.归档下载地址:

https://github.com/2amigos/yii2-qrcode-helper/archive/master.zip

2.将下载的包解压重名为2amigos,放到/vendor/2amigos

3.找到/vendor/yiisoft/extensions.php,添加以下代码到数组中

'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',
        ),
  ),

4.在控制器中写入下列代码

use dosamigosqrcodeQrCode;

class index{

     /**
     * @name 生成二维码
     * **/
    public function actionQrcode()
    {
        return Qrcode::png("baidu.com");

    }
}

5.在视图中写入下列代码

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

本文参照http://www.yii-china.com/post/detail/19.html

原文地址:https://www.cnblogs.com/fangjiali/p/6600046.html