thinkphp控制器裡怎麼使用require

來源:互聯網
上載者:User
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);

下面所有的你引入的檔案類,都加一個 \


果然有用,謝謝!
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.