How to import models from another Yii Application ?

Dear All,

So, I have this application structure, and I want to import all models, and components within the application1.


wwwroot

   yiiapp

      //START APPLICATION 1

      application1         

         protected

            config

               main.php

            controllers

            models

            view

            .

            .

            .

         themes

            application1_theme

         index.php

      //END APPLICATION 1


      //START OTHER APPLICATION

      protected

         config

            main.php

         controllers

         models

         .

         .

         .

      themes

         sometheme

      index.php

     //END OTHER APPLICATION



Now, from the OTHER APPLICATION, I want to make use models and components which I have created in APPLICATION1, how am I going to import those to my OTHER APPLICATION ? Is it even possible ?

Thank you!

Can’t you just include the proper path information into include_path?

(Please be aware of path precedence, as Yii imports directories in such way so that they have higher priority.)

Hi, thanks for the reply pestaa. Yes, indeed, I could include them using the include_path. However, I was wondering if Yii itself supports importing classes across multiple applications.

Well, for now, here is how to import other classes in another application into current application:

In the config/main.php file, instead of replacing the include_path, you can just join the existing include_path with your new include path, here it goes, just insert these before the [font="Courier New"]return array([/font]


<?php

ini_set('include_path', 

	   ini_get('include_path') . PATH_SEPARATOR . 

	   $_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'sitename'.DIRECTORY_SEPARATOR.'application1'.DIRECTORY_SEPARATOR.'protected'.DIRECTORY_SEPARATOR.'models');

The line where:

The line where:

Cheer folks!

A more "Yiiish" way might be to add a custom alias and add that to the import section of your main.php:


Yii::setPathOfAlias('myOtherApp','/other/applications/path/to/protected');

 return array(

     // ...

     'import' => array(

         // ...

         'myOtherApp.models.*',

 // ...

 );

Finally, the more Yiish way! Yes, thank you!