Yii 1.1: qr-code-generator

An extension allows you to create QR Barcode Generator
31 followers

An extension allows you to create QR Barcode Generator

Requirements

Yii 1.1 or above

Usage

extract the files under extension folder

Please read the Readme File for more informations

<?php $this->widget('application.extensions.qrcode.QRCodeGenerator',array(
    'data' => 'http://www.bryantan.info',
    'subfolderVar' => false,
    'matrixPointSize' => 5,
    'displayImage'=>true, // default to true, if set to false display a URL path
    'errorCorrectionLevel'=>'L', // available parameter is L,M,Q,H
    'matrixPointSize'=>4, // 1 to 10 only
)) ?>

Resources

Total 6 comments

#18941 report it
aknatn at 2015/02/07 06:26pm
URL as data content

If you are having issues with URLs as data content simply set the filename argument. The script attempts to save the QR image file with the data as the file name by default. I used the model id for reuse later and to keep each QR code unique.

<?php $this->widget('application.extensions.qrcode.QRCodeGenerator',array(
                            'data' => 'http://www.someurl.com',
                            'filename' => $model->id.".png",
                            'subfolderVar' => false,
                            'matrixPointSize' => 5,
                            'displayImage'=>false,
                            'errorCorrectionLevel'=>'L',
                            'matrixPointSize'=>4, // 1 to 10 only
                        )) ?>

Thanks for the extension, it works perfect for my use case!

#17596 report it
seletar6 at 2014/07/07 06:16am
Solving 500 Error

Assume you have place the extension such that the QRCodeGenerator.php is under protected/extensions/qrcode folder.

  1. Create a folder "uploads" under at the same level as your protected folder. Make sure it's writable.
  2. QRCodeGenerator.php make use of the "data" as filename for the QR code picture, which may not be valid file name. For example, 'http://www.bryantan.info' is not a valid file name. You need to sanitize it. I find two ways of sanitizing it.

a) Following function remove invalid characters from data so that it can be used as file name.

private function sanitizeFileName($string, $force_lowercase = true, $anal = false) {
        $strip = array("~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "=", "+", "[", "{", "]",
            "}", "\\", "|", ";", ":", "\"", "'", "&#8216;", "&#8217;", "&#8220;", "&#8221;", "&#8211;", "&#8212;",
            "—", "–", ",", "<", ".", ">", "/", "?");
        $clean = trim(str_replace($strip, "", strip_tags($string)));
        $clean = preg_replace('/\s+/', "-",
 $clean);
        $clean = ($anal) ? preg_replace("/[^a-zA-Z0-9]/", "", $clean) : $clean ;
        return ($force_lowercase) ?
            (function_exists('mb_strtolower')) ?
                mb_strtolower($clean, 'UTF-8') :
                strtolower($clean) :
            $clean;
    }

b) But it is necessary to use whole data as file name? We may just use a shorter hash string instead.

private function getHashString($string){
        $result = base_convert(md5($string), 16, 36);
        return $result;
    }
#15862 report it
织梦者 at 2013/12/24 02:57am
Error

data value such as "http://www.bryantan.info" can't be used to create file,but when data is "www.bryantan.info", it works

#15555 report it
Samir IZZA at 2013/11/21 05:30am
Usefull

Thanks Bryan for this extension

#13143 report it
fennellgb at 2013/05/07 04:43pm
500 Error

If you are getting a 500 does not exist look at the code in the file QRCodeGenerator.php. You may need to adjust $this->filePath. Code below is what I changed mine to work.

if (!$this->filePath){
    $this->filePath = realpath(__DIR__.'/../../../images/uploads');
}
#12937 report it
Girish at 2013/04/22 01:19am
Error

It shows following error.

Error 500 does not exists.

Could you please help?

Leave a comment

Please to leave your comment.

Create extension
Downloads