thinkphp控制器里怎么使用require

php中文网
发布: 2016-06-23 13:07:05
原创
3249人浏览过

public function search_edit(){
        // including all required classes
        require_once('d:\wamp64\www\aier\public\admin\barcodegen\class\bcgfontfile.php');
        require_once('d:\wamp64\www\aier\public\admin\barcodegen\class\bcgcolor.php');
        require_once('d:\wamp64\www\aier\public\admin\barcodegen\class\bcgdrawing.php');
        
        $codebar = bcgcode39; //条形码将要数据的内容
        
        // including the barcode technology
        require_once('d:\wamp64\www\aier\public\admin\barcodegen\class\barcode.php');
        
        // loading font
        $font = new bcgfontfile('./font/arial.ttf', 12);
        
        // the arguments are r, g, b for color.
        $color_black = new bcgcolor(0, 0, 0);
        $color_white = new bcgcolor(255, 255, 255);
        
        $drawexception = null;
        try {
            $code = new $codebar();//实例化对应的编码格式
            $code->setscale(2); // resolution
            $code->setthickness(23); // thickness
            $code->setforegroundcolor($color_black); // color of bars
            $code->setbackgroundcolor($color_white); // color of spaces
            $code->setfont($font); // font (or 0)
            $text = 'dfdf'; //条形码将要数据的内容
            $code->parse($text);
        } catch(exception $exception) {
            $drawexception = $exception;
        }
        
        /* here is the list of the arguments
         1 - filename (empty : display on screen)
         2 - background color */
        $drawing = new bcgdrawing('', $color_white);
        if($drawexception) {
            $drawing->drawexception($drawexception);
        } else {
            $drawing->setbarcode($code);
            $drawing->draw();
        }
        
        // header that says it is an image (remove it if you save the barcode to a file)
        header('content-type: image/png');
        
        // draw (or save) the image into png format.
        $drawing->finish(bcgdrawing::img_format_png);
}

报错:
class 'admin\controller\bcgfontfile' not found

require是成功了,但require里的变量无法找到,用不了。

阿里云-虚拟数字人
阿里云-虚拟数字人

阿里云-虚拟数字人是什么? ...

阿里云-虚拟数字人 2
查看详情 阿里云-虚拟数字人


回复讨论(解决方案)

试试
$font = new  \BCGFontFile('./font/Arial.ttf', 12);

下面所有的你引入的文件类,都加一个  \

试试
$font = new  \BCGFontFile('./font/Arial.ttf', 12);

下面所有的你引入的文件类,都加一个  \


果然有用,谢谢!
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号