Please help me with the setting up Yii2 as 3rd in another framework

Hi everyone,

Any one know about config to load classes in Autoload with configuration extensions.php

I have one problem when try to use Yii2 (as 3rd library) in another framework. It can not load the classes to AutoLoad even config well with yii/extensions.php

Here is how I do:

Step 1:

I create blank project and following the guide in Yii2 then I can have setup well, the project folder structure like here:


/index.php  --> main entry-point

/yii_init.php --> init yii

/composer.json

/yii/config/(main.php,main-local.php...)

/vendor/yiisoft/yii2

/vendor/yiisoft/yii2-composer

/vendor/yiisoft/extensions.php

In yii_init.php I have code is:


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


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

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

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

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

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

);

new yii\web\Application($config);

Here I do not call run() function.

In index.php code is:


require($_SERVER["DOCUMENT_ROOT"]."/yii_init.php");

echo "<pre>";

print_r(Yii::$app);

echo "</pre>";



It display well, mean that Yii2 seem setup well here.

Step 2: Error when try to use Extension

The error occurs when I try to add mylib (extensions) /vendor/mylib/app

This extension run very well when I run in Yii2 Basic or Advance, but when I copy this extension to this project, it CAN NOT.

I’ve tried config in extensions.php like in Yii2 such as:


$vendorDir = dirname(__DIR__);


return [

'mylib/app' => 

  array (

    'name' => 'mylib/app',

    'version' => '1.0',

    'alias' => 

    array (

      '@mylib' => $vendorDir . '/mylib/app',

    ),

  ),

];

And I also tried add more config in main.php like


 'aliases' => [

    '@mylib' => '@vendor/mylib/app',

  ],

But it still error when I try to use it in entry-point, it seem mylib still not add to Autoload and can not be load here, and I still don’t know how to use it.


use \mylib\models\MyModel;

$post = \mylib\models\MyModel::find()->where()->all();

var_dump($post);



It got error


Class 'mylib\models\MyModel' not found

So, Can Anyone help me on this case?

By the way can I using controller and assets (bootstrap) of Yii2 in 3rd like when use in Yii2 (Basic or Advance)

Thank you very much for your help!