I have been working through the getting started guide for Yii. After generating the CRUD code I receive an error when clicking on the "View/Edit/Delete" buttons. It appears that the generated links are incorrect in that they reference "id" rather than "code" (which is the primary key).
E.g the View link is
http://localhost/yii/demo/basic/web/index.php?r=country%2Fview&id=AU
which generates the error
Bad Request (#400)
Missing required parameters: code
when I manually change the link to
http://localhost/yii/demo/basic/web/index.php?r=country%2Fview&code=AU
it works correctly. Why is it referencing "id"?
I also had to modify the CountryController.php file, findModel function which was again referencing "id"
if (($model = Country::findOne($id)) !== null) {
when changed to "code" this worked.
protected function findModel($code)
{
if (($model = Country::findOne($code)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
Does anyone have any ideas, the db is MySQL and the Code column is defined as the Primary Key.
This is a bug in the current yii code.
It expects ID to be the primary key always
A way of fixing it would be to remove the action column from the gridview in index.php and add
Just got done going through old answers regarding how to change gridview to get to this.