1

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?

Oscar Reyes
  • 4,223
  • 8
  • 41
  • 75

2 Answers2

0

if your folder structure is like

-- root
-- protected
      |---- vendors
            |---- myfolder
                     |---- MyClass.php

you can import it like this

 Yii::import('appplication.vendors.myfolder.MyClass');

since yiis auto load is based on file name, if class Identicon was defined in MyClass it wont get loaded because it has different file name, so in this case you have to go with:

 Yii::import('appplication.vendors.myfolder.*' , true);
Developerium
  • 7,155
  • 5
  • 36
  • 56
  • sorry, but i tried both ways, on trying `Yii::import('application.vendor.Identicon.Identicon');` gives me "class not found" error. atleast it no longer gives me the "failed to open", im not sure if this has to do something with the library settings. ill check more about this – Oscar Reyes Aug 19 '14 at 05:30
  • do you have some kind of caching mechanism? is apc installed? – Developerium Aug 19 '14 at 06:06
  • i have it as vendor, and i dont think i have any cashing mechanism – Oscar Reyes Aug 19 '14 at 06:31
0

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.
Oscar Reyes
  • 4,223
  • 8
  • 41
  • 75