How to develop barcode function in thinkphp5
Jennifer
Jennifer 2018-04-12 13:09:43
0
0
1145

I want to implement a function that can generate barcodes in the system and use a barcode scanner to scan the barcodes to enter and exit the warehouse. I use thinkphp5 for development. I searched a lot of information and took the following steps. 1. Copy the barcode class folder barcode to the extend directory. 2. Add this sentence define('EXTEND_PATH','../extend/'); to the entry file. 3. Add a method to the self-built base.php file in common

< ;?php

namespace app\admin\common;


##use think\Controller;

use think\Request;

use Util\data\Sysdb;

use think\Session;


class Base extends Controller


{

public function barcode_create(){

$content='123';

// Reference the class corresponding to the barcode folder

Loader::import ('BCode.BCGFontFile',EXTEND_PATH);

//Loader::import('BCode.BCGColor',EXTEND_PATH);

Loader::import('BCode.BCGDrawing',EXTEND_PATH );

// Barcode encoding format

Loader::import('BCode.BCGcode39',EXTEND_PATH,'.barcode.php');

// $ code = '';

// Load font size

//$font = new BCGFontFile('./class/font/Arial.ttf', 18);

//Color barcode

$color_black = new \BCGColor(0, 0, 0);

$color_white = new \BCGColor(255, 255, 255);

$drawException = null;

try

{

$code = new \BCGcode39();

$code->setScale(2) ;

using with using using - code->setBackgroundColor($color_white); // White space color

// $code-> content); // The data content required by the barcode

} }

catch(\Exception $exception)

using ’s ‐ using through using through through out through out through out out through out out over ’'s' ’ ‐ ‐ ‐ ‐ ‐ } ‐ } to catch(\Exception $exception)

##}

// Draw the barcode

Series#$ Drawing = New \ BCGDRAWING ('', $ color_white) if it is based on the above conditions. {

$drawing->drawException($drawException);

}else{

$drawing->setBarcode($code); ;draw();

}

using using using ’ ’s ’ through through ’’s out through through off ‐ through through ‐ over‐‐‐‐‐‐‐ } to // header('Content-Disposition:attachment; filename="barcode.png"'); //Automatic download

$drawing->finish(\BCGDrawing::IMG_FORMAT_PNG);

}

Did I write it correctly? What to do next?

Jennifer
Jennifer

reply all (0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!