user17045604
user17045604

Reputation:

How to transform url into the correct form in the Yii2 framework

This code <?php echo Url::to(['/tasks/', 'view' => $task->id]);?> transforms into the url web/tasks?view=1 what code and where will transform output variants into the web/tasks/view/1?

Upvotes: 1

Views: 34

Answers (1)

user206
user206

Reputation: 1105

Config File:

'urlManager' => [
        # code...
        'rules' => [
            'tasks/view/<id:\d+>' => 'tasks/view',
         ],

Controller-Action

  public function actionView($id) {
     // $_GET or  \Yii::$app->getRequest()->GET('id')
     $id = ... int id
     # code..
  }

View File:

 <?php echo Url::to(['/tasks/view', 'id' => $task->id]);?>

Upvotes: 0

Related Questions