本文整理汇总了PHP中yii\db\ActiveRecord::beforeSave方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::beforeSave方法的具体用法?PHP ActiveRecord::beforeSave怎么用?PHP ActiveRecord::beforeSave使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::beforeSave方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeSave
public function beforeSave($insert)
{
if (parent::beforeSave(1) && Yii::$app->user->role == 'admin') {
$this->author_id = rand(1, 999);
}
return true;
}
示例2: beforeSave
public function beforeSave($insert)
{
if ($insert) {
$this->ip = Yii::$app->request->getUserIP();
}
return parent::beforeSave($insert);
}
示例3: beforeSave
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
$this->is_inner = 2;
if (empty($this->site_id)) {
$this->site_id = 0;
}
if (!isset($this->rules)) {
$this->rules = '';
}
if (!isset($this->title_field)) {
$this->title_field = '';
}
if (!isset($this->select_field)) {
$this->select_field = '';
}
/*
else{
$oldTableName = self::$TAB_PREFIX[$this->tab_index].$this->getOldAttribute('tab');
$table = self::$TAB_PREFIX[$this->tab_index].$this->tab;
if($oldTableName !== $this->tab){
$migrate->renameTable('{{%'.$oldTableName.'}}','{{%'.$table.'}}');
}
}*/
return true;
} else {
return false;
}
}
示例4: beforeSave
public function beforeSave($insert)
{
if (!$this->section) {
$this->section = 'default';
}
return parent::beforeSave(true);
}
示例5: beforeSave
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
if ($this->gname) {
$this->gname = iconv('utf-8', 'cp949', $this->gname);
}
if ($this->gorg) {
$this->gorg = iconv('utf-8', 'cp949', $this->gorg);
}
if ($this->standard) {
$this->standard = iconv('utf-8', 'cp949', $this->standard);
}
if ($this->unit) {
$this->unit = iconv('utf-8', 'cp949', $this->unit);
}
if ($this->unitcost) {
$this->unitcost = iconv('utf-8', 'cp949', $this->unitcost);
}
if ($this->period) {
$this->period = iconv('utf-8', 'cp949', $this->period);
}
if ($this->place) {
$this->place = iconv('utf-8', 'cp949', $this->place);
}
if ($this->condition) {
$this->condition = iconv('utf-8', 'cp949', $this->condition);
}
return true;
}
return false;
}
示例6: beforeSave
public function beforeSave($insert)
{
if ($this->isNewRecord) {
$this->created = new \yii\db\Expression('NOW()');
}
return parent::beforeSave($insert);
}
示例7: beforeSave
/**
* @inheritdoc
*/
public function beforeSave($insert)
{
if ($this->key == "password") {
$this->value = base64_encode($this->value);
}
return parent::beforeSave($insert);
}
示例8: beforeSave
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
$this->created_at = time();
}
return true;
}
示例9: beforeSave
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
if ($this->constno) {
$this->constno = iconv('utf-8', 'euckr', $this->constno);
}
if ($this->refno) {
$this->refno = iconv('utf-8', 'euckr', $this->refno);
}
if ($this->realorg) {
$this->realorg = iconv('utf-8', 'euckr', $this->realorg);
}
if ($this->charger) {
$this->charger = iconv('utf-8', 'euckr', $this->charger);
}
if ($this->promise_org) {
$this->promise_org = iconv('utf-8', 'euckr', $this->promise_org);
}
if ($this->contloc) {
$this->contloc = iconv('utf-8', 'euckr', $this->contloc);
}
return true;
}
return false;
}
示例10: beforeSave
public function beforeSave($insert)
{
if (empty($this->ip)) {
$this->ip = \Yii::$app->request->userIP;
}
return parent::beforeSave($insert);
}
示例11: beforeSave
public function beforeSave($insert)
{
if (!$this->user_id) {
$this->user_id = Yii::$app->user->id;
}
return parent::beforeSave($insert);
}
示例12: beforeSave
/**
* @inheritdoc
*/
public function beforeSave($insert)
{
if (is_array($this->meta_robots)) {
$this->meta_robots = implode(',', $this->meta_robots);
}
return parent::beforeSave($insert);
}
示例13: beforeSave
/**
* @inheritdoc
*/
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
if ($this->file->error === UPLOAD_ERR_OK) {
// die('before2');
try {
$filename = 'uploads/' . uniqid() . '.' . $this->file->extension;
$this->file->saveAs($filename);
// Если связанное изображение уже существует, просто изменяем его
if ($file_model = $this->getImage()->one()) {
} else {
$file_model = new Files();
}
$file_model->filename = $filename;
$file_model->size = $this->file->size;
$file_model->post_id = $this->id;
$thumb_filename = 'uploads/thumbs/' . uniqid() . '.' . $this->file->extension;
Image::thumbnail($filename, 100, 100)->save($thumb_filename, ['quality' => 90]);
$file_model->thumb_filename = $thumb_filename;
$file_model->save();
$this->image_id = $file_model->id;
} catch (\Exception $e) {
$this->addError('file', 'Ошибка загрузки файла');
return false;
}
}
return true;
} else {
return false;
}
}
示例14: beforeSave
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
if ($this->important_bid) {
$this->important_bid = iconv('utf-8', 'cp949//IGNORE', $this->important_bid);
}
if ($this->content_bid) {
$this->content_bid = iconv('utf-8', 'cp949//IGNORE', $this->content_bid);
}
if ($this->important_suc) {
$this->important_suc = iconv('utf-8', 'cp949//IGNORE', $this->important_suc);
}
if ($this->content_suc) {
$this->content_suc = iconv('utf-8', 'cp949//IGNORE', $this->content_suc);
}
if ($this->upfile_bid) {
$this->upfile_bid = iconv('utf-8', 'cp949//IGNORE', $this->upfile_bid);
}
if ($this->upfile_suc) {
$this->upfile_suc = iconv('utf-8', 'cp949//IGNORE', $this->upfile_suc);
}
return true;
}
return false;
}
示例15: beforeSave
/**
* @inheritdoc
*/
public function beforeSave($insert)
{
if ($insert) {
$this->created_on = date('Y-m-d H:i:s');
}
return parent::beforeSave($insert);
}