CActiveRecord.delete()

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.');

    }

Looks like your model failed to load (maybe it was successfully deleted already and you’re just refreshing a cached page which is still listing it?)

it’s not deleting the record at all

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.

when i do:


$daytrip = $this->loadDaytrip();

            

            print_r($daytrip);

            

            $daytrip->delete();

it wil print the object first and than delete it.

but it will give an error:

CException

Omschrijving

Property "Daytrip.id" is not defined.

Bronbestand

/home/bas/projects/yii.dev/private_html/framework/db/ar/CActiveRecord.php(106)