insert current date to mysql automatically in yii framework

here is example to show how could you insert current date before save in yii !

just use beforSave function in your model,

public function beforeSave(){
    $mysqldate = date( 'Y-m-d H:i:s');
    $this->addedDate = $mysqldate;

    return parent::beforeSave();
}

addedDate is the name of your column that hold your insert date ( time and date )

put this function in the model that you want to save added date in it !

yii framework automatically calls this function before save your data 😉

About the Author: mohammad

Leave a Reply

Your email address will not be published. Required fields are marked *