Integrate Yii2 Into Yii1

Update: Add log.

Use Yii2 in Yii1.1

I try test again today, still have errors.

  1. I am new download yii2-basic template by composer try to avoid other issue.

  2. The yii2-basic can run smoothly if I set it as standalone project.

  3. My existing demo (use yii1.1.15 framework) also work well

  4. I am planning Integrate yii2-basic into Yii 1.1.

The folder structure as below:

web root

	yii  //1.1 framework

	yii2-basic  //2.0 framework

	demo //1.1 real project









	        index.php //add yii2 settings accordingly.



$yii2MainFolder = __DIR__ . '/../yii2-basic';    // htdocs/demo/yii2-basic  

require(__DIR__ . '/protected/components/Yii.php');

$yii2Config = require($yii2MainFolder . '/config/web.php');

$Yii2 = new yii\web\Application($yii2Config); //this sentence cause issue, the program can run if I comment this line.  



$yii2path = $yii2MainFolder . '/vendor/yiisoft/yii2';  //htdocs/yii2-basic/vendor/yiisoft/yii2

require($yii2path . '/BaseYii.php'); // Yii 2.x

$yii1path = __DIR__ . '/../../../yii/framework';   //htdocs/yii/framework

require($yii1path . '/YiiBase.php'); // Yii 1.x

class Yii extends \yii\BaseYii {

// copy-paste the code in YiiBase (1.x) here

... may copied code from yii 1.1....


Yii::$classMap = include($yii2path . '/classes.php');

Yii::registerAutoloader(['Yii', 'autoload']);

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

The error as below, please help to check and advise, thanks.

[31-Oct-2014 15:45:33] exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "site/error".' in C:\xampp\htdocs\yii2-basic\vendor\yiisoft\yii2\base\Module.php:461

Stack trace:

#0 C:\xampp\htdocs\yii2-basic\vendor\yiisoft\yii2\web\ErrorHandler.php(79): yii\base\Module->runAction('site/error')

#1 C:\xampp\htdocs\yii2-basic\vendor\yiisoft\yii2\base\ErrorHandler.php(95): yii\web\ErrorHandler->renderException(Object(CException))

#2 [internal function]: yii\base\ErrorHandler->handleException(Object(CException))

#3 {main}

Previous exception:

exception 'CException' with message 'Property "CLogger.dispatcher" is not defined.' in C:\xampp\htdocs\yii\framework\base\CComponent.php:173

Stack trace:

#0 C:\xampp\htdocs\yii2-basic\vendor\yiisoft\yii2\log\Dispatcher.php(127): CComponent->__set('dispatcher', Object(yii\log\Dispatcher))

#1 C:\xampp\htdocs\yii2-basic\vendor\yiisoft\yii2\log\Dispatcher.php(115): yii\log\Dispatcher->setLogger(Object(CLogger))

#2 C:\xampp\htdocs\yii2-basic\vendor\yiisoft\yii2\log\Dispatcher.php(87): yii\log\Dispatcher->getLogger()

#3 [internal function]: yii\log\Dispatcher->__construct(Array)

#4 C:\xampp\htdocs\yii2-basic\vendor\yiisoft\yii2\di\Container.php(364): ReflectionClass->newInstanceArgs(Array)

#5 C:\xampp\htdocs\yii2-basic\vendor\yiisoft\yii2\di\Container.php(147): yii\di\Container->build('yii\log\Dispatc...', Array, Array)

#6 C:\xampp\htdocs\yii2-basic\vendor\yiisoft\yii2\BaseYii.php(344): yii\di\Container->get('yii\log\Dispatc...', Array, Array)

#7 C:\xampp\htdocs\yii2-basic\vendor\yiisoft\yii2\di\ServiceLocator.php(133): yii\BaseYii::createObject(Array)

#8 C:\xampp\htdocs\yii2-basic\vendor\yiisoft\yii2\base\Application.php(302): yii\di\ServiceLocator->get('log')

#9 C:\xampp\htdocs\yii2-basic\vendor\yiisoft\yii2\web\Application.php(63): yii\base\Application->bootstrap()

#10 C:\xampp\htdocs\yii2-basic\vendor\yiisoft\yii2\base\Application.php(267): yii\web\Application->bootstrap()

#11 C:\xampp\htdocs\yii2-basic\vendor\yiisoft\yii2\base\Object.php(107): yii\base\Application->init()

#12 C:\xampp\htdocs\yii2-basic\vendor\yiisoft\yii2\base\Application.php(206): yii\base\Object->__construct(Array)

#13 C:\xampp\htdocs\demo\index.php(41): yii\base\Application->__construct(Array)

#14 {main}

$_SERVER = [... omit here since no need this info for analysis ...]

See below.

Please post the full error you see.

Delete this item, see latest details at below.

As said before: Please post the full error you see. Including stack trace.

Add log at first post, thx.

@Cebe, can you check and revert? thx.

I have also undergone the same problem while integrating Yii2 in Yii1.1.12.Can anyone assist me with detail solution.

If anyone else have same problem:

In Yii2 config remove/comment out

'bootstrap' => ['log'],

line. This seems to mess everything up.

Or when copying YiiBase (1.x) content, remove getLogger() function. I guess you might also need to get rid of log/trace/beginProfile/endProfile functions. But application seem to work if you just remove getLogger() function, but I guess there might be problems when you try to use Yii2 logger, so keep that in mind :)