Error In "using Yii2 With Yii1"

I followed the Using Yii2 with Yii1 carefully and it led to the following error:





PHP message: PHP Fatal error:  Call to a member function get() on a non-object in /Volumes/Sites/yii2yii/vendor/yiisoft/yii2/BaseYii.php on line 344

PHP message: PHP Stack trace:

PHP message: PHP   1. {main}() /Volumes/Sites/yii2yii/web/index.php:0

PHP message: PHP   2. yii\base\Application->__construct() /Volumes/Sites/yii2yii/web/index.php:729

PHP message: PHP   3. yii\base\Application->registerErrorHandler() /Volumes/Sites/yii2yii/vendor/yiisoft/yii2/base/Application.php:199

PHP message: PHP   4. yii\base\Application->getErrorHandler() /Volumes/Sites/yii2yii/vendor/yiisoft/yii2/base/Application.php:330

PHP message: PHP   5. yii\di\ServiceLocator->get() /Volumes/Sites/yii2yii/vendor/yiisoft/yii2/base/Application.php:502

PHP message: PHP   6. yii\BaseYii::createObject() /Volumes/Sites/yii2yii/vendor/yiisoft/yii2/di/ServiceLocator.php:132




The problem is that BaseYii::$container is not set when line 344 in YiiBase is executed




        return static::$container->get($class, $params, $type);



I tried adding


Yii::$container = new yii\di\Container;

in the bootstrap before instantiating the Yii2 app. That led to various errors because the autoloader was looking for Yii1 class files in the Yii2 framework base.

Next I tried instantiating the Yii1 app first. That had the same problem, autoloader looking for Yii1 classes in the Yii2.

So I have the feeling this page of the guide is out of step with current code. Is there example code online that’s known to be working with current master? Or perhaps not and you can tell from the above what mistake I’ve made.

https://github.com/slavcodev/yii-bridge ?

I think the problem can be fixed by reversing the order of including YiiBase and BaseYii… i.e. change




$yii2path = '/path/to/yii2';

require($yii2path . '/BaseYii.php');

$yii1path = '/path/to/yii1';

require($yii1path . '/YiiBase.php');



to




$yii1path = '/path/to/yii1';

require($yii1path . '/YiiBase.php');

$yii2path = '/path/to/yii2';

require($yii2path . '/BaseYii.php');



I think it’s a matter of who gets to define the YII_PATH global constant.

I’m trying your bridge script, but getting this error

yii\base\InvalidConfigException

Unknown component ID: i18n

I’ve attached my entry script.

hi, mr @samdark we have a project in yii1 and we are working in it since one year ago, is it possible to go to yii2 with yii-bridge ? what is your offer?