Yii Framework Forum: Aftersave Dan Beforesave - Yii Framework Forum

Jump to content

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

Aftersave Dan Beforesave Rate Topic: -----

#1 User is offline   kfahmi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 19-March 12

Posted 04 October 2012 - 11:11 PM

Ada yang mau ngajarin ane gak? cara penggunaan aftersave dan before save??


selama ini ane pake cara ane sendiri, mau cobain pake aftersave sama before save nya yii. ada yang bersedia ngajarin atau paste salah satu code nya disini :)


thanks
0

#2 User is offline   siskalandre 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 92
  • Joined: 16-March 11
  • Location:Indonesia

Posted 08 October 2012 - 06:07 AM

public function beforeSave() {
        $this->invoicedate = date(Yii::app()->params['datetodb'], strtotime($this->invoicedate));
		$this->amount = str_replace(",","",$this->amount);
		$this->rate = str_replace(",","",$this->rate);
    return parent::beforeSave();
}



View Postkfahmi, on 04 October 2012 - 11:11 PM, said:

Ada yang mau ngajarin ane gak? cara penggunaan aftersave dan before save??


selama ini ane pake cara ane sendiri, mau cobain pake aftersave sama before save nya yii. ada yang bersedia ngajarin atau paste salah satu code nya disini :)


thanks

0

#3 User is offline   dyooolicious 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 18-October 12
  • Location:Surabaya, East Java, Indonesia

Posted 30 October 2012 - 11:37 PM

View Postkfahmi, on 04 October 2012 - 11:11 PM, said:

Ada yang mau ngajarin ane gak? cara penggunaan aftersave dan before save??


selama ini ane pake cara ane sendiri, mau cobain pake aftersave sama before save nya yii. ada yang bersedia ngajarin atau paste salah satu code nya disini :)


thanks


ini script afterSave-nya kalo mau bikin counter, misalnya berapa banyak buku yang dipunya sama seorang pengarang :

public function afterSave() {
        $count = Buku::model()->countByAttributes(array('id_pengarang' => $this->id_pengarang));

        $pengarang = Pengarang::model()->findByPk($this->id_pengarang);
        $pengarang->jumlah_buku = $count;
        $pengarang->save();
    }

keep learning, trying and praying makes you keep going !
tweet me : @dyooolicious
http://ini-infonya.blogspot.com/
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