您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

thinkphp控制器里怎么使用require

2024/4/2 3:50:26发布27次查看
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里的变量无法找到,用不了。
回复讨论(解决方案) 试试
$font = new  \bcgfontfile('./font/arial.ttf', 12);
下面所有的你引入的文件类,都加一个  \
试试
$font = new  \bcgfontfile('./font/arial.ttf', 12);
下面所有的你引入的文件类,都加一个  \
果然有用,谢谢!
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product