phpqrcode在PHPCMF中的实现代码
1、把phpqrcode包放到thinkcmf根目录的simplewind/extend里。
2、
$file_name = "{$this->id}.png";// 计算记录对应的子文件路径(防止每个文件夹内保存的图片数量超过系统限制)$sub_dir = num_divide_dir_path($this->id); $local_dir = "/upload/qrcode/{$sub_dir}"; $local_path = $local_dir."/".$file_name; $full_dir = ROOT_PATH."public".$local_dir; $full_path = $full_dir."/".$file_name;if(!file_exists($full_path)){ if(!is_dir($full_dir)){ mkdir($full_dir, 0777, true); } // 这是生成图片的主要方法 import('phpqrcode.phpqrcode',EXTEND_PATH); \QRcode::png("http://www.baidu.com", $full_path); }//把图片路径传到view页面
$this->assign("qrcode_img", $local_path);
实现代码如下(测试通过):
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use cmf\controller\HomeBaseController;
import('phpqrcode.phpqrcode',EXTEND_PATH);
class InheritController extends HomeBaseController
{
public function index()
{
$value = 'http://www.taijiquanpu.com/public/zhaobao/213.html'; //二维码内容
$errorCorrectionLevel = 'L';//容错级别
$matrixPointSize = 6;//生成图片大小
//生成二维码图片
\QRcode::png($value, 'qrcode.png', $errorCorrectionLevel, $matrixPointSize, 2);
echo '<img src="/public/qrcode.png">';
return $this->fetch(':inherit');
}
}