How to get Yii instance outside Yii framework

Hi all,

How we can get Yii instance outside of Yii framework.

eg:

I use yii framework and another framework. for authentication user, I use Yii, but sometime when we on another framework, I need to determine authentication user using (Yii::app()->user->isGuest).

How can I get Yii instance on outside of Yii framework? Anyone have an Idea, please share…

Thanks in advance,

You can create an instance…

just don’t do run to the application

You can use Registry for that, for example Zend_Registry

as this:




Yii::createWebApplication($config);



you should NOT use




Yii::createWebApplication($config)->run();



Hm… Completely from my mind, without testing (sorry, no time for that). You would do this just as you do this in your index.php application?


$config = dirname(__FILE__).'/protected/configuration/general.php';


Yii::createWebApplication($config)->user->isGuest;

But you have to test it yourself…

http://www.yiiframework.com/doc/guide/1.1/en/extension.integration#using-yii-in-3rd-party-systems

Mike,

Never run into this section, but +1 for you for reminding this, as this proves again and again, how powerful Yii is, which makes my day just a little bit brighter! :]

Trejder

Thank all master, your answer very useful for me :).

Will doing this create session variables? There are some frameworks which break when you mess around with the session before they load, even if they have different ids.

No. Yii is built on top of PHP’s built in session system. So session id will be the same. And it will not write to the session unless your code does it or when you login through Yii.

Hi am trying to implement this too, I have tried the below code




//Using Yii in third party libs

require_once('../Open_Accounts/framework/yii.php');

$config = '../Open_Accounts/protected/config/main.php';

Yii::createWebApplication($config);



However the result is a that it loads my default controller view




Yii::createWebApplication($config)->run();



I think run() is being called by default am using Yii 1.1.12

I have got a solution, it seems that even without


run()

Yii requires that you have a writable assets folder, so create one and have it writable