Question

I am trying to extend my yii application with solarium extension (extension for solr in php) .

However , the library for the extension had multiple sub directories . As a result I have to include files from specific sub directories like this :

Yii::import('application.extensions.Library.Solarium.*');
Yii::import('application.extensions.Library.Solarium.Client.*');
Yii::import('application.extensions.Library.Solarium.Client.RequestBuilder.*');

This leads to ugly code as well as unpredictability if I have included all files or not .Though I am doing this in the action currently I will move it to config later for production . Is there any other convenient way to include all files from the directories and sub directories ? There are a lot of sub directories and so mentioning each one would lead into 20-30 lines of code . One option is to place all library files in a single directory for production . However I am not sure if it would affect functionality (I am generically 'new' to implementing extensions/libraries) .

Was it helpful?

Solution

When i'm adding 3rd party classes to Yii, i put them in a folder under protected/components/, like /protected/components/solr.

Then in the main configuration i add the following lines to the import section:

'import' => array(
      'application.components.solr.*',
      ...

But you need to add each subfolder one by one, this is due to perfomance issues, Yii's developers removed recursive import some releases ago. If you think that'll sucks, then you can use namespaces to do what you want, but you'll need PHP 5.3

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top