I'm stuck. I'm trying to run some function from the command shell.
I'm using the HelloController from the basic project.
When I run php yii hello
it's working good and the index function is running but if I try to run different function like php yii hello/create
I'm getting this error -
Error: Unknown command.
I added the create function to this controller.
The strange thing is that when I run php yii
I'm seeing the create command.
My controller code
namespace app\commands;
use yii\console\Controller;
use Yii;
class HelloController extends Controller
{
public function actionIndex($message = 'hello world')
{
echo $message . "\n";
}
public function actionCreate($message = 'hello world')
{
echo $message . "\n";
}
}
UPDATED: My Config file is
Yii::setAlias('@tests', dirname(__DIR__) . '/tests');
$params = require(__DIR__ . '/params.php');
$db = require(__DIR__ . '/db.php');
return [
'id' => 'basic-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log', 'gii'],
'controllerNamespace' => 'app\commands',
'modules' => [
'gii' => 'yii\gii\Module',
],
'components' => [
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@app/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => '...',
'username' => '...',
'password' => '...',
'port' => '...',
//'encryption' => 'tls',
],
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'authManager' => [
'class' => 'yii\rbac\DbManager',
],
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => $db,
],
'params' => $params,
];
Does anyone know how to solve this issue? Thanks.