Using yii2 advanced with yii1

I have been developing a site in yii1. I was using a structure similar to the advance template. I had done the backend and a bit of frontend but now since yii 2 is out i wish to use yii2 for future dev. So this is what i did

  1. Downloaded yii2 advanced template code

  2. moved my model, view, controller n component from 1.1 to backend of 2.0

  3. moved config etc to a new folder inside config

  4. Changed entry script and followed the steps in

http://www.yiiframework.com/doc-2.0/guide-tutorial-yii-integration.html#using-yii-2-with-yii-1

but i get Property "CLogger.dispatcher" is not defined.

index.php




<?php

defined('YII_DEBUG') or define('YII_DEBUG', true);

defined('YII_ENV') or define('YII_ENV', 'dev');




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


require(__DIR__ . '/../../vendor/autoload.php');

require(__DIR__ . '/../../common/config/bootstrap.php');

require(__DIR__ . '/../config/bootstrap.php');


$yii2config = yii\helpers\ArrayHelper::merge(

    require(__DIR__ . '/../../common/config/main.php'),

    require(__DIR__ . '/../../common/config/main-local.php'),

    require(__DIR__ . '/../config/main.php'),

    require(__DIR__ . '/../config/main-local.php')

);


$application = new yii\web\Application($yii2config);

$application->run();


/* YII 1.1 */

$yii1config = require(__DIR__ . '/../config/yii1/main.php');

#Yii::setPathOfAlias('site', __DIR__ . '/../../');

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



yii2 main.php




<?php

$params = array_merge(

    require(__DIR__ . '/../../common/config/params.php'),

    require(__DIR__ . '/../../common/config/params-local.php'),

    require(__DIR__ . '/params.php'),

    require(__DIR__ . '/params-local.php')

);


return [

    'id' => 'app-backend',

    'basePath' => dirname(__DIR__),

    'controllerNamespace' => 'backend\controllers',

    'bootstrap' => ['log'],

    'modules' => [],

    'components' => [

        'user' => [

            'identityClass' => 'common\models\User',

            'enableAutoLogin' => true,

        ],

        'log' => [

            'traceLevel' => YII_DEBUG ? 3 : 0,

            'targets' => [

                [

                    'class' => 'yii\log\FileTarget',

                    'levels' => ['error', 'warning'],

                ],

            ],

        ],

        'errorHandler' => [

            'errorAction' => 'site/error',

        ],

    ],

    'params' => $params,

];



yii1 main.php

[code]

<?php

// uncomment the following to define a path alias

// Yii::setPathOfAlias(‘local’,‘path/to/local-folder’);

// This is the main Web application configuration. Any writable

// CWebApplication properties can be configured here.

return array(

'basePath'=&gt;dirname(__FILE__).DIRECTORY_SEPARATOR.'..',


'name'=&gt;'JustFilmy',





// preloading 'log' component


'preload'=&gt;array('log'),





// autoloading model and component classes


'import'=&gt;array(


    'site.common.models.*',


	'application.models.*',


    'site.common.components.*',


	'application.components.*',


	'site.common.extensions.*'


),





'modules'=&gt;array(


	// uncomment the following to enable the Gii tool


	'gii'=&gt;array(


		'class'=&gt;'system.gii.GiiModule',


		'password'=&gt;'giiisawesome',


		// If removed, Gii defaults to localhost only. Edit carefully to taste.


		'ipFilters'=&gt;array('127.0.0.1','::1'),


		'generatorPaths'=&gt;array(


            'application.gii',   // a path alias


        ),


	),


),





// application components


'components'=&gt;array(


	'user'=&gt;array(


		// enable cookie-based authentication


		'allowAutoLogin'=&gt;true,


		'class' =&gt; 'WebUser',


	),





	// uncomment the following to enable URLs in path-format


	'urlManager'=&gt;array(


		'urlFormat'=&gt;'path',


        'showScriptName'=&gt;false,


		'rules'=&gt;array(


			'&lt;controller:&#092;w+&gt;/&lt;id:&#092;d+&gt;'=&gt;'&lt;controller&gt;/view',


			'&lt;controller:&#092;w+&gt;/&lt;action:&#092;w+&gt;/&lt;id:&#092;d+&gt;'=&gt;'&lt;controller&gt;/&lt;action&gt;',


			'&lt;controller:&#092;w+&gt;/&lt;action:&#092;w+&gt;/&lt;id:&#092;d+&gt;/*'=&gt;'&lt;controller&gt;/&lt;action&gt;',


			'&lt;controller:&#092;w+&gt;/&lt;action:&#092;w+&gt;'=&gt;'&lt;controller&gt;/&lt;action&gt;',


		),


	),


	'clientScript'=&gt;array(


	    'scriptMap'=&gt;array(





	    )


	),


	'db'=&gt;array(


			'connectionString' =&gt; 'mysql:host=localhost;dbname=reviewengine',


			'emulatePrepare' =&gt; true,


			'username' =&gt; 'root',


			'password' =&gt; '',


			'charset' =&gt; 'utf8',


			'tablePrefix' =&gt; 're_'


	),


	'errorHandler'=&gt;array(


		// use 'site/error' action to display errors


		'errorAction'=&gt;'site/error',


	),


	'log'=&gt;array(


		'class'=&gt;'CLogRouter',


		'routes'=&gt;array(


			array(


				'class'=&gt;'CFileLogRoute',


				'levels'=&gt;'error, warning',


			),


			array(


		       'class'=&gt;'CWebLogRoute',


		       'categories'=&gt;'system.db.CDbCommand',


		    )


		),


	)


),





// application-level parameters that can be accessed


// using Yii::app()-&gt;params['paramName']


'params'=&gt;array(


	// this is used in contact page


	'adminEmail'=&gt;'we

Faced exactly same problem today;

I Added 2 fields in {yii1 folder}/logging/CLogger.php

    public &#036;dispatcher;


    public &#036;traceLevel;

This solved my problem

setup "logger" in yii2 main.php




        'log' => [

            'logger' => Yii::createObject('yii\log\Logger'),

            'traceLevel' => YII_DEBUG ? 3 : 0,

            'targets' => [

                [

                    'class' => 'yii\log\FileTarget',

                    'levels' => ['error', 'warning'],

                ],

            ],

        ],



2 Likes