Bad Request (#400) - Getting started Tutorial

Hi there,
Im new at yii and followed the tutorial guide.
I have an issue at the last step, while using Gii code generator.

The system created the code using CRUD, but it seems that it isnt working correctly. The database entries are listed and I can even add a new entry in the DB, but when I try to update, delete or view a single entry, it throws me an yii\web\BadRequestHttpException: Missing required parameters: code i error when clicking on the icon for updating, deleting or viewing

Hi @chdrsto, welcome to the forum.

Sounds very strange. Might be a bug in Gii.

Could you show us what urls the icons represent? For example, what url does the “view” icon has?

And, one more thing, could you show us the schema for the country table?

Hi @softark , thanks for answering.
The icons are pointing to following urls on one entry (it seems that new user can only post two links)

Server is : http://localhost:8080/

It is a MariaDB with following schema:
Greenshot 2021-12-19 08.56.12

Thank you.

It seems like a bug in Gii’s CRUD generator.
The country/index page creates a URL of “country/view?id=SR” for the view page of “SR”, but it should be “country/view?code=SR” because the PK is ‘code’.

One quick (and dirty) workaround might be renaming the parameter of actionView():

// pubulic function actionView($code)
pubulic function actionView($id)
{
    return $this->render('view', [
        // 'model' => $this->findModel($code),
        'model' => $this->findModel($id),
    ]);
}

I will examine the problem a little further. My guess is that the Gii’s CRUD generator might fail to produce the right code when the model’s PK is not ‘id’.

Oh, this is it.
Not a bug of Gii, but a bug in yii\grid\ActionColumn.

Thanks for your lookup on github.
It is funny that I’m the first one who trapped into that bug while doing the tutorial :slight_smile:
Anyway, it was interesting to start with debugging eventhough I had no idea on what am I doing

1 Like

I also have no idea why this bug has been hidden from many people for this long. :sweat_smile:
Has there been no one that faithfully followed the tutorial step by step before you?
Good grief. :tired_face:

1 Like