Search code examples
phpyiiidenticon

Yii, importing library does not work


i'm trying to implement Identicon library to my site but i get the error that class is not found.

i tried with Yii::import('application.vendor.*'); so i put the library in vendor folder, but it does not work.

i also tried adding the library to the component controller but still gives me the error.

and i tried making the import in the view where the code will be

<?php
    Yii::import('application.vendor.*');
    $identicon = new Identicon;

    $identicon->displayImage('test');
?>

and yet it tells me the error that this class is not found. i just copied the src folder from the zip to vendors and components. how can i import this library?


Solution

  • i finally imported Identicon library by editing every file from the library and store it into components/Identicon.

    it seems like the use of namespaces that each file had on the code wasn't allowing Yii to import, so it works by deleting the namespaces and the use command on every file, then import it in the config file.

    'import'=>array(
            'application.models.*',
            'application.components.*',
            'application.components.Identicon.*'
    ),
    

    Note: All files found in generator must be in the same folder that Identicon.php is place.

    so you can use the library almost like the readme from Identicon says

    $Identicon = new Identicon;
    
    $identicon->displayImage('foo'); //Displays the image.