Yii Framework Forum: CActiveRecord.delete() - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CActiveRecord.delete() Fatal error: Call to a member function delete() Rate Topic: -----

#1 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

Posted 09 November 2009 - 03:57 AM

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

0

#2 User is offline   Sander 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 169
  • Joined: 03-November 09
  • Location:Amsterdam, Netherlands

Posted 09 November 2009 - 05:25 AM

View Postbas_vdl, on 09 November 2009 - 03:57 AM, said:

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?)
0

#3 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

Posted 09 November 2009 - 05:40 AM

it's not deleting the record at all
0

#4 User is offline   Sander 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 169
  • Joined: 03-November 09
  • Location:Amsterdam, Netherlands

Posted 09 November 2009 - 05:50 AM

View Postbas_vdl, on 09 November 2009 - 05:40 AM, said:

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.
0

#5 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

Posted 09 November 2009 - 08:34 AM

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)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users