Yii 安装二维码扩展Qrcode

 

比如要添加 https://github.com/2amigos/yii2-qrcode-helper 生成二维码的 这个扩展
第一种方法 :
    1、打开根目录的composer.json, 在require那里加上 "2amigos/yii2-qrcode-helper" : "~1.0",如图
    "require": {

     "php": ">=5.4.0",
     "yiisoft/yii2": "*",
     "yiisoft/yii2-bootstrap": "*",
     "yiisoft/yii2-swiftmailer": "*",
  "2amigos/yii2-qrcode-helper" : "~1.0"

    },

   2、命令行切换到根目录, 运行composer update,等几分钟就好了

   3、按照扩展的说明做些配置
第二种方法 :

php composer.phar require 2amigos/yii2-qrcode-helper:~1.0  
composer require 2amigos/yii2-qrcode-helper:~1.0
在SiteController.php中

1 use dosamigos\qrcode\QrCode;
2 use dosamigos\qrcode\formats\MailTo;
3 
4 public function actionQrcode() {
5         $mailTo = new MailTo(['email' => 'xp796@163.com']);
6         return QrCode::png($mailTo); 
7     }

在index.php 中

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

成功

posted @ 2016-06-08 11:34  哦先生  阅读(6738)  评论(1编辑  收藏  举报