简体   繁体   中英

Codeigniter + Zend barcode error at Zend/Barcode/Barcode.php

I always have this error:

Parse error: syntax error, unexpected T_STRING in /home/user/public_html/nameofsite/application/libraries/Zend/Barcode/Barcode.php on line 10

Here is my controller code for generating barcode:

public function testbarcode()
{
    require_once('./application/libraries/Zend/Barcode/Barcode.php');
    //adjust the above path to the correct location
    $barcodeOptions = array('text' => 'ZEND-FRAMEWORK');
    $rendererOptions = array();
    Zend_Barcode::factory('code39', 'image', $barcodeOptions, $rendererOptions)->render();
}

Barcode.php code:

namespace Zend\\Barcode; //this is line 10

use Traversable; use Zend\\Stdlib\\ArrayUtils;

/** * Class for generate Barcode */ abstract class Barcode { . . . more code }

What could be the solution here? I tried a lot of search with this but no luck at all I'm using codeigniter 2.1.3 and zend 2.2.1

It should be

use namespace Zend\Barcode; //this is line 10

Parse error: syntax error, unexpected T_STRING says it found a string, although this string was not expected. It could be expecting a colon, ie

Anyway, the require that uses Zend\\Barcode should be BEFORE the use. And by what I know, you should require the autoloader for BarCode, not the class directly.

Copy the Zend folder to codeigniter's system/libraries/ and load lib as following

public function testbarcode()
{
    $this->load->library('zend');
    $this->zend->load('Zend/Barcode');

    $barcodeOptions = array('text' => 'ZEND-FRAMEWORK');
    $rendererOptions = array('imageType'=>'png', 'horizontalPosition' => 'center', 'verticalPosition' => 'middle');
    Zend_Barcode::factory('code39', 'image', $barcodeOptions, $rendererOptions)->render();
    return $imageResource;
}

I Hope, Its helpful

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM