Last active
February 24, 2018 10:08
-
-
Save pptyasar/035351fdaf6b352d566dcace7cb838ae to your computer and use it in GitHub Desktop.
Yii2 copy paste snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//afterSave | |
public function afterSave($insert, $changedAttributes) | |
{ | |
if ($insert){ | |
//New record | |
}else{ | |
//Old record | |
} | |
parent::afterSave($insert, $changedAttributes); | |
} | |
//beforeSave | |
public function beforeSave($insert) | |
{ | |
if (parent::beforeSave($insert)) { | |
if($this->isNewRecord){ | |
$this->created_date = date("Y-m-d H:i:s"); | |
} | |
return true; | |
} else { | |
return false; | |
} | |
} | |
//generateRandomString | |
Yii::$app->security->generateRandomString() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment