История изменений поста

Общие вопросы по использованию второй версии фреймворка. Если не знаете как что-то сделать и это про Yii 2, вам сюда.
Закрыто
madgen
Сообщения: 15
Зарегистрирован: 2018.09.17, 17:02

История изменений поста

Сообщение madgen »

Ещё раз добрый день, пытаюсь сделать историю изменений поста, используя afterSave, в котором будет производиться запись значений из таблицы deal в таблицу dealhistory

Код: Выделить всё

public function afterSave($insert, $changedAttributes)
    {
        parent::afterSave($insert, $changedAttributes);

        $dealHistory = new Dealhis;
        $dealHistory->deal_id=$this->id;
        $dealHistory->author_id=$this->author_id;
        $dealHistory->type=$this->type;
        $dealHistory->name=$this->name;
        $dealHistory->subtype=$this->subtype;
        $dealHistory->stage=$this->stage;
        echo $dealHistory->deal_id;
        if($dealHistory->save())
        {
            return true;
        }
       
    }

Пост обновляется, а вот запись в dealhistory не производится
Не подскажите что делать?


Модель

Код: Выделить всё

<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "dealhis".
 *
 * @property int $id
 * @property int $author_id
 * @property string $created_at
 * @property string $type
 * @property string $subtype
 * @property string $stage
 * @property string $concurrence_number
 * @property string $investigative_body
 * @property string $court_name
 * @property string $deal_link
 * @property string $document
 * @property string $ep_number
 * @property string $bailiffs
 * @property string $plot
 * @property string $deal_order
 * @property string $name
 * @property string $imageFiles
 * @property string $n_body
 * @property string $notary
 * @property string $start_document
 * @property string $end_document
 * @property string $start_at
 * @property string $end_at
 * @property string $r_place
 * @property string $r_site
 * @property string $deal_id
 */
class Dealhis extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'dealhis';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['author_id', 'name',  ], 'required'],
            [['author_id'], 'integer'],
            [['created_at', 'start_document', 'end_document', 'start_at', 'end_at'], 'safe'],
            [['type', 'subtype', 'deal_id', 'stage', 'user_id'], 'string', 'max' => 25],
            [['concurrence_number', 'court_name', 'deal_link', 'ep_number', 'bailiffs', 'plot', 'deal_order', 'n_body', 'r_place', 'r_site'], 'string', 'max' => 255],
            [['investigative_body', 'name', 'notary'], 'string', 'max' => 40],
            [['document'], 'string', 'max' => 30],
            [['imageFiles'], 'string', 'max' => 50],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'author_id' => 'Author ID',
            'created_at' => 'Created At',
            'type' => 'Type',
            'subtype' => 'Subtype',
            'stage' => 'Stage',
            'concurrence_number' => 'Concurrence Number',
            'investigative_body' => 'Investigative Body',
            'court_name' => 'Court Name',
            'deal_link' => 'Deal Link',
            'document' => 'Document',
            'ep_number' => 'Ep Number',
            'bailiffs' => 'Bailiffs',
            'plot' => 'Plot',
            'deal_order' => 'Deal Order',
            'name' => 'Name',
            'imageFiles' => 'Image Files',
            'n_body' => 'N Body',
            'notary' => 'Notary',
            'start_document' => 'Start Document',
            'end_document' => 'End Document',
            'start_at' => 'Start At',
            'end_at' => 'End At',
            'r_place' => 'R Place',
            'r_site' => 'R Site',
        ];
    }


}
Аватара пользователя
carono
Сообщения: 52
Зарегистрирован: 2018.04.28, 11:05

Re: История изменений поста

Сообщение carono »

проверь массив с ошибками в модели $dealHistory после её сохранения
andku83
Сообщения: 988
Зарегистрирован: 2016.07.01, 10:24
Откуда: Харьков

Re: История изменений поста

Сообщение andku83 »

Код: Выделить всё

        if( ! $dealHistory->save())
        {
            var_dump($dealHistory->errors);
        }
madgen
Сообщения: 15
Зарегистрирован: 2018.09.17, 17:02

Re: История изменений поста

Сообщение madgen »

Проблема была в deal_id, спасибо за ответы!
Закрыто