This extension based on "Simple jQuery Based Barcode Generator" Wrapper for BarCode Coder Library (BCC Library Version 2.0) by DEMONTE Jean-Baptiste, HOUREZ Jonathan.
Licence : GPL / Cecill.
[Web site]( http://barcode-coder.com/ "")
Barcode types supported: ¶
EAN 8, EAN 13, UPC, standard 2 of 5 (industrial), interleaved 2 of 5, code 11, code 39, code 93, code 128, codabar, MSI, Data Matrix,
Output formats supported: ¶
CSS, BMP (not usable in IE), Canvas (not usable in IE).
Requirements ¶
- Yii Version 1.1.13 or later
Usage ¶
- Extract the downloaded zip file and place it inside application extensions directory.
Use the following code as per your requirement.
"div" or "canvas" must be specified with an id in your view where you want to display the bracode "<" div id="showBarcode" ">""<"/div">" OR if output option is canvas "<"canvas id="showBarcode" width="150" height="150"">""<"/canvas">"
- Version 1.2 update Fixed the Bug Regarding CDetail View not displaying. Removed div element creation inside the extension, which causes this bug with Yii framework 1.1.15.
- Version 1.1 update Same as the previous but no need of the div element, minor modification of the Common Class function.
Helper Class Common under models (No need to call the extension initialization): ¶
class Common{
/* bracode */
public static function getItemBarcode($valueArray) {
$elementId = $valueArray['itemId'] . "_bcode"; /*the div element id*/
$value = $valueArray['barocde'];
$type = 'code128'; /* you can set the type dynamically if you want valueArray eg - $valueArray['type']*/
self::getBarcode(array('elementId' => $elementId, 'value' => $value, 'type' => $type));
return CHtml::tag('div', array('id' => $elementId));
}
/**
* This function returns the item barcode
*/
public static function getBarcode($optionsArray) {
Yii::app()->getController()->widget('ext.barcode.Barcode', $optionsArray);
}
}
Usage with helper class Common : ¶
- Usage with CGridView
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'st-item-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
'item_code',
array('name' => 'item_barcode', 'type' => 'raw', 'value'=>'Common::getItemBarcode(array("itemId"=> $data->item_id, "barocde"=>$data->item_barcode))'),
),
));
- Usage with CDetail View
$this->widget('zii.widgets.CDetailView', array(
'data' => $model,
'attributes' => array(
array(
'name' => 'item_barcode',
'type'=>'raw',
'value' => Common::getItemBarcode(array("itemId"=> $model->item_id, "barocde"=>$model->item_barcode))
),
));
- Usage with a View
/* if multiple barcodes make sure itemId is unique*/
$optionsArray = array(
'itemId'=> 'barcode-div', /*id for div or canvas */
'barocde'=> '4797001018719', /* value for EAN 13 be careful to set right values for each barcode type */
'type'=>'ean13',/*supported types ean8, ean13, upc, std25, int25, code11, code39, code93, code128, codabar, msi, datamatrix*/
);
echo Common::getItemBarcode($optionsArray);
Initialize the widget in your view regular way by initializing the widget ¶
echo '<div id="showBarcode"><div>'; //the same id should be given to the extension item id
$optionsArray = array(
'elementId'=> 'showBarcode', /*id of div or canvas*/
'value'=> '4797001018719', /* value for EAN 13 be careful to set right values for each barcode type */
'type'=>'ean13',/*supported types ean8, ean13, upc, std25, int25, code11, code39, code93, code128, codabar, msi, datamatrix*/
);
$this->widget('ext.barcode.Barcode', $optionsArray);
- Widget with advanced options
- Kindly note there are specific settings for canvas output and datamatrix type if not set default settings will be applied.
$optionsArray = array(
'elementId'=>'showBarcode',
'value'=>'4797001018719',
'type' => 'code128',
'settings'=>array(
'output'=>'css' /*css, bmp, canvas note- bmp and canvas incompatible wtih IE*/,
/*if the output setting canvas*/
'posX' => 10,
'posY' => 20,
/* */
'bgColor'=>'#00FF00', /*background color*/
'color' => '#000000', /*"1" Bars color*/
'barWidth' => 1,
'barHeight' => 50,
/*-----------below settings only for datamatrix--------------------*/
'moduleSize' => 5,
'addQuietZone' => 0, /*Quiet Zone Modules */
),
'rectangular'=> true /* true or false*/
/* */
);
Easy to use
Using this extension couldn't be any easier. I had multiple barcodes with different values on the same page within 5 minutes of downloading it. Thanks for providing it.
@jward
Thank you, I'm happy it's useful to you, hats off to Yii staff for awesome framework and this plugin creaters , Jean-Baptiste and HOUREZ Jonathan.
Nice Extension
Nice work dude :)..
@Rohit Suthar
Thanks man, new version is available if you like to update your extension.
SVG repair
Correctly generate SVG must be replaced (in jquery-barcode.min.js):
var u = document.createElement("object"); u.setAttribute("type", "image/svg+xml"); u.setAttribute("data", "data:image/svg+xml," + n); this.resize(q, p).append(u)
to
//var u = document.createElement("object"); //u.setAttribute("type", "image/svg+xml"); //u.setAttribute("data", "data:image/svg+xml," + n); this.resize(q, p).append(n)
@Xolegator
Thanks
CDetailView
Hi!
I'm trying to use this on CDetailView, however, if do that, all the detail grid disappears and only the barcode shows up. What's wrong?
@ kAIOSHIN
Hi kAIOSHIN ,
Thanks for reporting the issue, I've added the div element creation within the extension, but it seems when echoing the the element it breaks the CDetail view, I'll look in to this but Below I'm listing a quick fix,
modify your barcode extension php file go to Project Folder/protected Folder/extensions Folder/ /barcode Folder/Barcode.php open this file
under the method "getBarcode()" last two lines before the return statement there will div element echoing on line 92 (echo CHtml::tag('div', array('id' => $this->elementId));) remove that code save the file and on your Common class method getItemBarcode()
add the div element returning code as below. don't echo it just return it. with CDetail view attribute setting type as "raw"
public static function getItemBarcode($valueArray) { $elementId = $valueArray['itemId'] . "_bcode"; $value = $valueArray['barocde']; $type = 'code128'; /* you can set the type dynamically if you want valueArray eg - $valueArray['type'] */ self::getBarcode(array('elementId' => $elementId, 'value' => $value, 'type' => $type)); return CHtml::tag('div', array('id' => $elementId)); }
Need example for bar code generator in Yii2
Hi,
can any one provide a example for how to use bar code generator in Yii2
thanks in advance
@ yogeshbansal
Hello Yogesh, Currently I'm developing this extension for Yii2, Probably end of this weekend, I'll be able to publish it.
@ yogeshbansal
The extension for Yii2 link
Save the barcode
How can I save this barcode to my directory in Yii? Thank you.
@Oscar Daniel Hutajulu
Hello Oscar,
Please download the extension and extract it to your project extension folder then, follow the instructions given in the documentation.
Documentation
Where can I get the documentation, Vilo? Thank you.
@Oscar
Hello Oscar, it's documented in this page, cheers.
Save Barcode into Image
There is no such thing in this page. Or would you like to show it to me?
@Oscar
Hello Oscar, sorry you cannot save the bar code as an image, and there is no need to do so, because it's dynamically created, if want to print it use a pdf library. then you can get the out put as a hard copy.
How to with yii 1.1.16
i have trying this extension but the barcode can not showing.. any solution for yii 1.1.16 ??
Thank you
Font Size
The default font size is 10, which is too small. You can change it with fontSize in Settings.
For example:
$optionsArray = array( 'elementId'=> 'showBarcode', /*id of div or canvas*/ 'value'=> $barcode, /* value for EAN 13 be careful to set right values for each barcode type */ 'type'=>'ean8',/*supported types ean8, ean13, upc, std25, int25, code11, code39, code93, code128, codabar, msi, datamatrix*/ 'settings'=>array( 'barWidth' => 1, 'barHeight' => 50, 'fontSize' => 14, ), );
Please help me
i got this error below error. when i run barcode generator.
this error
Uncaught TypeError: $(...).html(...).show(...).barcode is not a function
@rajavel3007 can you show sample of your implementation
Bom dia a todos!
Existe alguma extensão que possar ler esse código de barras com um leitor e automaticamente trazer dados para os textField "por exemplo"?
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.