I have a basic application with a few pages and commands tested and working.
Now I want to move it around in the file system.
I want to share the webroot with another php system.
So I rename index.php to y.php, and hard-code the paths:
<?php
require('/home/me/sites/ppv/vendor/autoload.php');
require('/home/me/sites/ppv//vendor/yiisoft/yii2/Yii.php');
$config = require('/home/me/sites/ppv/config/web.php');
(new yii\web\Application($config))->run();
Looks like it works, I can navigate the basic app ok.
But there are problems…
- A previously created alias is no longer available to me. I broke it. But how?
Then I notice this line at the top of config/console.php:
Yii::setAlias('@tests', dirname(__DIR__) . '/tests/codeception');
That seems odd. Why does it not use the alias config?
I add my own alias in a similar manner and poof it is available. Now I am confused. Wht did the configuration stop working?
Then I have trouble running some console tasks.
me: /yii cron/serial/test
BEGIN TEST
PHP Fatal error: Class 'app\common\components\Fcmd' not found in /home/me/sites/ppv/commands/cron/SerialController.php on line 60
So I know Yii is finding a controller nested in /commands/cron/SerialController and invoking the action.
But what happened to my FCmd component in /common/components?
namespace app\commands\cron;
use Yii;
use \yii\console\Controller;
use hank\hankDump;
use hank\hankKernal;
use app\models\kvs\Serials;
use app\models\kvs\Videos;
use app\common\components\Fcmd; /** EXPERIMENTAL **/
class SerialController extends TaskController
{
...
public function actionTest()
{
echo "BEGIN TEST\n";
$ffcmd = new Fcmd(); /** FAILED **/
$ffcmd = new \app\common\components\Fcmd(); /** FAILED **/
I have also added this line to my nginx config:
index index.php y.php index.html;
…but pretty urls fail with 404s. I do not care, I do not neeed pretty urls. But is that telling something?
Possibly related question:
Changing the name of index.php seems to be supported. Looks like Yii figures it out by itself.
Just the same, I find no documentation for what the value of ‘ScriptUrl’ should be in the UrlManager config.
Is it even relevant? Does it want the full protocol+domain+entry script, or is it just the entry script?
Not sure what I am looking for. I have renamed the enrty script for the web application.
Why has the console app broken?
I was careful to put my shared component in the common folder.
Here is the console config…
<?php
Yii::setAlias('@tests', dirname(__DIR__) . '/tests/codeception');
Yii::setAlias('@hank', '/home/me/sites/hank');/** THIS CORRECTS THE BROKEN CONFIG BELOW ****/
$params = require(__DIR__ . '/params.php');
$db = require(__DIR__ . '/db.php');
$config = [
'id' => 'basic-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'app\commands',
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => $db,
'ffcmd' => [
'class' => 'app\components\ffmeg', /*** I BROKE THIS ***/
],
],
'aliases' => [
'@hank' => '/home/me/sites/hank', /*** I BROKE THIS ***/
],
'params' => $params,
];
return $config;
Finally I should mention I am still pretty new to Yii and php namespaces. Learning fast but never fast enough…
Thank you for any advice.