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);
下面所有的你引入的檔案類,都加一個 \
果然有用,謝謝!