0

I've create button view profile at gridview. When user click the button view profile, it will go to profile based on user_id. Here is the code.

      <?= GridView::widget([
 'dataProvider' => $dataProvider,
 'id' => 'mygrid',
 'columns' => [
    ['class' => 'yii\grid\SerialColumn'],
    'user_id',
    'project_name',
    ['class' => 'yii\grid\ActionColumn'],
    [
        'label' => 'View Profile',
        'format' => 'raw',
        'content' => function($model) {
            return Html::a('View', ['projectstudent/viewprofile', 'id' =>     $model->user_id],
                ['class' => 'btn btn-primary']);
        }
    ],
]
 ]); ?>

At controller

    public function actionViewprofile($id)
{
 return $this->render('profile', [
        'model' => $this->findModel($id),
    ]);
}

The requested page is not found. How can i fix the code? Thanks.

Fyp16
  • 131
  • 1
  • 5
  • 16
  • Is controller named `ProjectstudentController`? – Bizley Nov 19 '16 at 11:22
  • yup @Bizley . The controller is Projectstudentcontroller. – Fyp16 Nov 19 '16 at 11:37
  • There might be several reasons: controller might be called in wrong way (be inside a module), UrlManager or server url rewriting rules might be wrong, on non-Windows environments file name case might be wrong... There is not enough information from you to tell for sure. – Bizley Nov 19 '16 at 11:51
  • Update your question and show your controller code .. – ScaisEdge Nov 19 '16 at 12:29
  • can you open your url directly in browser??? as same as localhost/projectstudent/viewprofile?id=1 – Jalali Nov 19 '16 at 13:03

1 Answers1

0

Here may be problem of controller name that u are specified, there is no need to define controller name if you want to call the action of same controller.

So replace so your code with this and try again

 return Html::a('View', ['viewprofile', 'id' =>$model->user_id],
            ['class' => 'btn btn-primary']);
Mohan
  • 606
  • 4
  • 11