Hello, i try to delete a record using the linkButton. the way as in the blog tutorial but in my own project it’s deleting the records but it will give the error:
( ! ) Fatal error: Call to a member function delete() on a non-object in /home/bas/projects/yii.dev/private_html/protected/back-end/controllers/DaytripController.php on line 120
view:
<?php echo CHtml::linkButton('Verwijder', array('submit' => array('daytrip/delete', 'id' => $daytrip->IdDaytrip), 'confirm' => "Are you sure to delete this post?")); ?>
controller:
public function actionDelete() {
if(Yii::app()->request->isPostRequest)
{
$daytrip = $this->loadDaytrip();
$daytrip->delete();
$this->redirect(array('daytrip/list'));
}
else
throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
}
Well, then it probably fails to load for some other reason. I’m betting your call to $this->loadDaytrip(); is returning NULL, which obviously doesn’t have a delete() method (hence the error message). Try to find out why the model isn’t loading and work your way from there.