3

I want to automatically download my database backup weekly. I'm using xampp on windows. I've google around and found that I've to make use of windows task scheduler and the action script in my console controller. I've read this and this and tried running the command from command prompt. I'm getting 'Unknown command'.

My code in console controller for now just for testing

<?php
namespace console\controllers;


use Yii;
use yii\console\Controller;

/**
 * Cron controller
 */
class TestController extends Controller {

    public function actionIndex() {
        echo "cron service runnning";
  }

}

And my main config file

<?php
$params = array_merge(
    require(__DIR__ . '/../../common/config/params.php'),
    require(__DIR__ . '/../../common/config/params-local.php'),
    require(__DIR__ . '/params.php'),
    require(__DIR__ . '/params-local.php')
);

return [
    'id' => 'app-console',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'console\controllers',
    'components' => [
        'log' => [
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
         'authManager' => [
        'class' => 'yii\rbac\DbManager',
    ],
    ],

    'modules' => [
    'rbac' =>  [
        'class' => 'johnitvn\rbacplus\Module'
    ]       
],

    'params' => $params,
];

The error I'm getting enter image description here

4
  • try command yii. What message is returned? Commented Oct 30, 2016 at 16:13
  • I'm getting the available yii command list Commented Oct 31, 2016 at 6:43
  • 1
    i'm getting the same error. did you find a solution to your problem @gojiraki ? Commented Feb 21, 2017 at 11:25
  • Can you add the location of your "main.php"? Is it under "console\config"? Commented Mar 14, 2017 at 10:53

1 Answer 1

2

Make sure you have TestController.php file in console/controllers folder and its name is written correctly.

Then from project root folder you can call your command like that:

php yii test/index

or just:

php yii test

(because index is a default action (configured in $defaultAction) and you can omit it).

If you are outside of project folder, make sure to provide correct path:

php /path/to/project/folder/yii test
Sign up to request clarification or add additional context in comments.

3 Comments

Yeah! my file is in the console/controllers and I've already did what you have said but still not able to run the command from command prompt. Still getting unknown command
@gojiraki Please show how exactly you call it (full command) and full error message in this case.
Hi! I've edited my question and added the screenshot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.