Project running Yii1 & Yii2 - can't find debug Module

Hello

I’m trying to add Yii2 to an existing Yii1 project, following the instructions in the docs

But I am getting a 500 error





exception 'ReflectionException' with message 'Class yii\\debug\\Module does not exist' in /Volumes/home2/httpdocs/sfhv-new/_protected/vendor/yiisoft/yii2/di/Container.php:415

Stack trace:




I’m assuming this is a config error but cannot see what I’m doing wrong.

My project structure is

project dir —





    -- backend (Yii1 webroot)

        -- index.php (modified as per instructions)

    -- protected (Yii1 sources)

        -- components

            -- Yii.php (the combined Yii component)

    -- _protected (Yii2 sources)

       -- vendor

         -- Yii1

         -- Yii2

         -- etc




the contents of my index.php:





<?php


// include the customized Yii class described below

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




// configuration for Yii 2 application

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

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


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

//require(__DIR__ . '/../_protected/vendor/yiisoft/yii2/Yii.php');

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

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


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

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

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

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

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

);


new yii\web\Application($yii2Config); // Do NOT call run()


// change the following paths if necessary

// configuration for Yii 1 application

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


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




and the Yii.php component





$yii2path = '../_protected/vendor/yiisoft/yii2';

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


$yii1path = '../_protected/vendor/yiisoft/yii1';

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


class Yii extends \yii\BaseYii

{

// pasted code from YiiBase.php with getLogger commented out

}


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

// register Yii 2 autoloader via Yii 1

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

// create the dependency injection container

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




I’ve stepped through and it hits the error when trying to instantiate a new ReflectionClass in Container.php

415 $reflection = new ReflectionClass($class);

I presume it can’t find the class but don’t know why …


EDIT: App now running but cannot find Yii2 controllers

The fault seemed to be the order of calling and setting up environment variables, exacerbated by using the Improved Advanced template

However, I did have to comment out both Gii and Debug modules (for now).

My index.php now looks like this:-







// configuration for Yii 2 application

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

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


// include the customized Yii class described below

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


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

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


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

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

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

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

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

);


Yii::setAlias('webroot', dirname(__DIR__) . '/web');

Yii::setAlias('web', exec('hostname'));


new yii\web\Application($yii2Config); // Do NOT call run()


// change the following paths if necessary

// configuration for Yii 1 application

$yii1Config = require(__DIR__ . '/../protected/config/main.php');


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




QUESTION: Should I be able to call a Yii2 controller / action ???

Hey,

I’m too facing the same issue, it seem as the classes for the modules(debug,gii) are not getting loaded.

I installed them both using composer. I can see them loaded to the Yii::$app->extenstions. I was able to workaround the issue if I manually adding the classes of the modules to the classes.php file.

I think it’s related to something with the autoloader of the Yii 2.0 not being called properly…

can someone shed some light on working with modules and controllers in a Yii 1.0 -2.0 combined system?

I can’t see how Yii2 aliases will work with the given code. The YiiBase class is based on Yii1 which works on completely different Alias system.

I tried changing the code to call the Yii2 getAlias if Yii1 returned NULL but then I ran into namespace problems and still couldn’t get the classes to load.

I’ve given up for now and have decided to run the two systems side by side on similar sub-domians and then I’ll try and share the session and thus user-identity between the two by using sessions stored in the database … I haven’t got round to trying this yet though.

It seems to me that the intention was just to be able to use the occasional Yii2 widget or something similar (you would probably have to specify the full path) and not to integrate a full Yii1 app and a Yii2 app.