Home > PHP Framework > YII > How to generate QR code in yii2

How to generate QR code in yii2

王林
Release: 2020-02-17 16:25:35
Original
3478 people have browsed it

How to generate QR code in yii2

1、通过composer加载

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

或者添加

"2amigos/yii2-qrcode-helper" : "*"
Copy after login

到对应项目的composer.json文件中。

(推荐教程:yii框架

2、编辑/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',
    ),
 ),
Copy after login

3、在你的控制器中添加以下代码

use dosamigos\qrcode\QrCode;  //引入类
\\ ... 
public function actionQrcode() 
{ 
  return QrCode::png('http://www.yii-china.com');  //调用二维码生成方法
}
public function actionDemo()
{
  return $this->render('index');
}
Copy after login

在你的页面中添加以下代码 (demo/index)

<img src="<?= Url::to([&#39;index/qrcode&#39;])?>" />
Copy after login

访问demo这个方法就能看到一张漂亮的二维码了。

更多编程相关内容,请关注php中文网编程教程栏目!

The above is the detailed content of How to generate QR code in yii2. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template