Yii 1.1: yii-barcode-generator-8-types

This extension supports barcode types ean8, ean13, upc, std25, int25, code11, code39, code93, code128, codabar, msi, datamatrix
10 followers

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

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*/
 /* */
);

Resources

Total 18 comments

#19758 report it
kuncolaksmono at 2016/01/20 11:28pm
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

#19457 report it
Vilo at 2015/07/14 01:25am
@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.

#19455 report it
Oscar Daniel Hutajulu at 2015/07/13 12:16am
Save Barcode into Image

There is no such thing in this page. Or would you like to show it to me?

#19441 report it
Vilo at 2015/07/09 12:51am
@Oscar

Hello Oscar, it's documented in this page, cheers.

#19440 report it
Oscar Daniel Hutajulu at 2015/07/08 10:20pm
Documentation

Where can I get the documentation, Vilo? Thank you.

#19439 report it
Vilo at 2015/07/08 09:23pm
@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.

#19436 report it
Oscar Daniel Hutajulu at 2015/07/07 11:54pm
Save the barcode

How can I save this barcode to my directory in Yii? Thank you.

#19257 report it
Vilo at 2015/04/30 03:38am
@ yogeshbansal

The extension for Yii2 link

#19255 report it
Vilo at 2015/04/29 01:32am
@ yogeshbansal

Hello Yogesh, Currently I'm developing this extension for Yii2, Probably end of this weekend, I'll be able to publish it.

#19250 report it
yogeshbansal at 2015/04/27 07:43pm
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

#18902 report it
Vilo at 2015/02/02 02:18am
@ 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));           
    }
#18898 report it
kAIOSHIN at 2015/02/01 07:20am
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?

#18568 report it
Vilo at 2014/11/19 02:14am
@Xolegator

Thanks

#18537 report it
Xolegator at 2014/11/12 08:42am
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)
#18473 report it
Vilo at 2014/11/04 06:00am
@Rohit Suthar

Thanks man, new version is available if you like to update your extension.

#18198 report it
Rohit Suthar at 2014/09/25 04:25am
Nice Extension

Nice work dude :)..

#18116 report it
Vilo at 2014/09/12 04:41am
@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.

#18115 report it
jward at 2014/09/12 01:02am
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.

Leave a comment

Please to leave your comment.

Create extension