Yii2: slug not working

246 views Asked by At

My PageController looks like:

namespace app\controllers;
use app\models\Page;
use yii\base\Controller;
use yii\web\NotFoundHttpException;

class PageController extends Controller
{

  public  function actionIndex($slug){
         var_dump($slug);exit;
  }
}

And my urlManager looks like this:

 'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
            'page/<slug>' => 'page/index',
        ]
    ],

When I hit a URL as http://localhost/myproject/page/about-us I get error:

Too few arguments to function app\controllers\PageController::actionIndex(), 0 passed and exactly 1 expected.

Am I missing something?

1

There are 1 answers

0
Bizley On

Instead of

use yii\base\Controller;

use

use yii\web\Controller;