Theme Is Null

My folder structure is like this







My basePath is pointing to protected directory. My main.php has theme name declared correctly.


However following code is returning NULL

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

    $yii_app = Yii::createWebApplication($config); 

    var_dump($yii_app->theme);   // prints NULL

And of course, rest of application does not see any theme being active and falls back to layouts within protected instead of my theme.


did you write the below code ?


Hi, Thanks for getting back.

I’m trying to write a wordpress plugin (plugin being an yii application).

And I’m following footsteps of

From the yiiapp_admin_actions method, I presumed that the yii application will be ran when the wordpress menu item was clicked. Please correct me if I understood the code wrongly.

So, I didn’t include a run() immediately next to the createWebApplication() call.

(my code is almost the same as the one in the link above)

Thanks again.

I didn’t use before this,

did you check if the other configurations has been initialized ? (for example check echo $yii_app->name)

also check if $yii_app::app()->theme works…

// var_dump($yii_app::app()->theme); ==> raises error as "Fatal error: Call to undefined method CWebApplication::app()"

var_dump($yii_app->name); ==> returns the application name correctly. It is only the theme name that is not working. :(

I understand that theme can be returned as Null if there are issues with casing of theme folder name etc. Are you aware of other possibilities that can result in the failure of theme intialization?

Or can you point me to the class file name that actually loads theme to memory? May be i can try put some debug statements there to find more.

Because you do not run the web application you can’t use Yii::app() eventually… so

$yii_app = Yii::createWebApplication($config); 

var_dump ($yii_app->name);

var_dump ($yii_app->theme); 



I test it and it works perfectly in my case

Are you sure that set theme correctly ? try also with $yii_app->name