A further note: I noticed that when viewing the demo’s the action for “updating” records it appears to be the same as the “create” action. What I mean is that they both use the “save” method, and what I find really strange is that there does not appear to be the “id” set in any of this. Generally when editing records in other applications there is always an “id” set so that the database knows which record to edit. But I have not seen this in Yii, is this true? How does the “id” get set when editing records?
In the default generated crud it gets the id from the _GET array when loadModel() is called at the beginning of the function - perhaps the loadModel function is what you need to take a look at to see how it ties together?
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
public function actionUpdate($id)
// Uncomment the following line if AJAX validation is needed
It does indeed take a parameter (GET).
But, of course, it will also work without. If the loadModel checks for $_GET[‘id’].
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
public function loadModel()
throw new CHttpException(404,'The requested page does not exist.');
And none of the actions takes parameters.
It was written against an older Yii which didn’t have automatic parameter binding.