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
)) ?>
Error
It shows following error.
Error 500
does not exists.
Could you please help?
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'); }
Usefull
Thanks Bryan for this extension
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
Solving 500 Error
Assume you have place the extension such that the QRCodeGenerator.php is under protected/extensions/qrcode folder.
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("~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "=", "+", "[", "{", "]", "}", "\\", "|", ";", ":", "\"", "'", "‘", "’", "“", "”", "–", "—", "—", "–", ",", "<", ".", ">", "/", "?"); $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; }
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!
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.