yiiyii2organizationapplication-structure

Application file re-organization in Yii 2


I have set up new Yii2 project. Now I want to reorganize folder structure in two folders "public" and "app" (which actually represents the protected files).

All the code from framework goes in "app" folder. In "public" folder I have only one script named "index.php" from where I'm calling the app. The code there looks like the following (I have only modified only the paths from the original "index.php").

app/index.php

<?php

// comment out the following two lines when deployed to production
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

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

$config = require(__DIR__ . '/../app/config/web.php');

(new yii\web\Application($config))->run();

?>

This same approach was working in the Yii framework where we got different syntax of the commands. But now in Yii 2 I got the following issue:

enter image description here

So it seems like all the paths are pointing to the right files (I have check that), but I still got the error. So what I'm missing here? Why the basePath still recognize the "public" folder?

UPDATE 1:

After following the comment from @marche and add the following code to the config file:

'components' => [
    ...
    'assetManager' => [
        'basePath' => 'my/path/to/assets',
    ],
    ...
],

I'm not getting the error with the screen anymore, but now the content is loaded without any CSS styling and without JS files (they are still pulling URL from the wrong places).


Solution

  • I found the solution. In the "public" folder instead of just having the "index.php" script, I have moved the complete "web" folder from the "protected" folder (where actually all the assets and scripts were located).