How to use require in thinkphp controller

Source: Internet
Author: 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; Barcode will be the content of the data

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 is 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 ();//instantiate the corresponding encoding format
$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 '; Barcode will be the content of the data
$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's 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);
}

Error:
Class ' admin\controller\bcgfontfile ' not found

Require was successful, but the variables in the require could not be found and could not be used.


Reply to discussion (solution)

Give it a try
$font = new \bcgfontfile ('./font/arial.ttf ', 12);

All of the following file classes you introduce, add a \

Give it a try
$font = new \bcgfontfile ('./font/arial.ttf ', 12);

All of the following file classes you introduce, add a \


Sure is useful, thank you!
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.