URL-Rule doesn't work (404 error)

Hi guys, I’m totally confused. Calling delete method in my view results by error 404. Following url will be created:




http://localhost/yii2_perswitch/frontend/web/index.php/deleteRecords?id=5&render=%2Fdateianhang%2Fdateianhang%2Findex_without_id&FKBezeichnung=id_person



Here is Url-rule(PrettyUrl is true)




 'deleteRecords' => 'dateianhang/dateianhang/deleteRecords',



Herei s Methodname in Controller




 public function actionDeleteRecords($id, $render, $FkBezeichnung) { }



Here is calling method in View





    [

        'class' => 'yii\grid\ActionColumn',

        'template' => ' {view} {update} {deleteRecords}',

        'buttons' => [

            'deleteRecords' => function ($model, $id) {

                $go = "/dateianhang/dateianhang/deleteRecords";

                $render = "/dateianhang/dateianhang/index_without_id";

                $FKBezeichnung = "id_person";

                return Html::a('<span class="glyphicon glyphicon-trash"></span>', [$go, 'id' => $id->id, 'render' => $render, 'FKBezeichnung' => $FKBezeichnung], ['title' => 'Löschen', 'data' => ['pjax' => '0']]);

            },

        ],

    ],



Any ideas what I do wrong?

The signature of the button rendering callback must be ($url, $model, $key).

http://www.yiiframework.com/doc-2.0/yii-grid-actioncolumn.html#$buttons-detail




            'deleteRecords' => function ($url, $model) {

                $go = "/dateianhang/dateianhang/deleteRecords";

                $render = "/dateianhang/dateianhang/index_without_id";

                $FKBezeichnung = "id_person";

                return Html::a('<span class="glyphicon glyphicon-trash"></span>', [$go, 'id' => $model->id, ...]);

            },



Problem is not in using wrong button rendering. Problem seems to be wrong URL rule. If I code like this, everything is gonna all right.

Url rule:




 'dateianhang_delete' => 'dateianhang/dateianhang/del',



Methodname in Controller[




public function actionDel($id, $RenderBackInCaseOfError, $FkBezeichnung) {}



[color="#1C2837"][size="2"]Calling method in View[/size][/color]

[color="#1c2837"][size="2"]


[

'class' => 'yii\grid\ActionColumn','template' => '{view} {update} {delete_records}',

        'buttons' => 

            'delete_records' => function ($model, $id) {

                $RenderBackInCaseOfError = "/dateianhang/dateianhang/index_without_id";

                $FkBezeichnung = "id_person";

                return Html::a('<span class="glyphicon glyphicon-trash"></span>', ['/dateianhang/dateianhang/del', 'id' => $id->id, 'RenderBackInCaseOfError' => $RenderBackInCaseOfError, 'FkBezeichnung' => $FkBezeichnung], ['title' => 'Löschen', 'data' => ['pjax' => '0']]);

            }

        ]



[/size][/color]

It’s not all right using parameters having shown up im my first thread

A url is in the format of “URL_PATTERN => ROUTE”. There’s no wonder ‘dateianhang/dateianhang/deleteRecords’ didn’t work, because it means “deleteRecords” action of “dateianhang” controller of “dateianhang” module, while you have ‘del’ action instead.

Why don’t you fix the signature? IMO, “$id->id” is not only misleading but also very ugly.

I followed ur opinion and fixed signature,too

Special thanks to U…