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