Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the coder-elementor domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/u262393194/domains/codestap.com/public_html/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the rank-math domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/u262393194/domains/codestap.com/public_html/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the rocket domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/u262393194/domains/codestap.com/public_html/wp-includes/functions.php on line 6114
How do you create custom commands using Yii’s console application? - Code Stap
How do you create custom commands using Yii’s console application?

How do you create custom commands using Yii’s console application?

To create custom commands using Yii’s console application, follow these steps:

Step 1: Create a Console Command Class

  1. In commands/, create a new PHP file for your custom command, for example, HelloController.php.
  2. This class should extend yii\console\Controller.

Example

<?php
namespace app\commands;

use yii\console\Controller;

class HelloController extends Controller
{
    public function actionIndex()
    {
        echo "Hello, World!\n";
    }
}
?>

Step 2: Configure Console Application

In the config/console.php file, configure the controllerNamespace if needed.

Example

<?php
return [
    'id' => 'console-app',
    'basePath' => dirname(__DIR__),
    'controllerNamespace' => 'app\commands',
];
?>

Step 3: Run the Command

To execute the custom command, use the following in the terminal:

Example

php yii hello/index

You can also add parameters to the command:

Example

<?php
public function actionIndex($name = 'Guest')
{
    echo "Hello, $name!\n";
}
?>

To run with parameters:

Example

php yii hello/index John

This is how you create and run custom commands in Yii’s console application.

Related Questions & Topics