Setting up Controller

Hello im new to yii2 framework and I have just added a controller but when trying to run the application im getting a 404 here is my implementation

  1. <?php
  2. namespace backend\controllers;

  3. use yii\web\Controller;

  4. class HelloController extends Controller

  5. {

  6. public function actionIndex()
    
  7. {
    
  8.     return "Hello World";
    
  9. }
    
  10. }

and my main.php i config

  1. <?php$params = array_merge(
  2. require __DIR__ . '/../../common/config/params.php',    require __DIR__ . '/../../common/config/params-local.php',
    
  3. require DIR . '/params.php',    require DIR . '/params-local.php'
    
  4. );
  5. return [ ‘id’ => ‘app-backend’,
  6. 'basePath' => dirname(__DIR__),    'controllerNamespace' => 'backend\controllers',
    
  7. 'bootstrap' => ['log'],    'modules' => [],
    
  8. 'components' => [        'request' => [
    
  9.         'csrfParam' => '_csrf-backend',        ],
    
  10.     'user' => [            'identityClass' => 'common\models\User',
    
  11.         'enableAutoLogin' => true,            'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
    
  12.     ],        'session' => [
    
  13.         // this is the name of the session cookie used for login on the backend            'name' => 'advanced-backend',
    
  14.     ],        'log' => [
    
  15.         'traceLevel' => YII_DEBUG ? 3 : 0,            'targets' => [
    
  16.             [                    'class' => \yii\log\FileTarget::class,
    
  17.                 'levels' => ['error', 'warning'],                ],
    
  18.         ],        ],
    
  19.     'errorHandler' => [            'errorAction' => 'site/error',
    
  20.     ],        
    
  21.     'urlManager' => [            'enablePrettyUrl' => true,
    
  22.         'showScriptName' => false,            'rules' => [
    
  23.         ],
    
  24.     ],        
    
  25. ],    'params' => $params,
    
  26. ];

please help me set it up.The default Site controler is working well

How are you trying to access it?

It should be something like http://localhost/hello

or

http://localhost/hello/index

/index isn’t really needed since it’s the default action name.