Могу ли я вызвать сам класс в статическом методе в PHP?

В Yii2 в классе Active Recorda хочу создать статический метод чтобы потом его вызывать в разных местах кода.

<?php

namespace app\modules\api_v1\models;

    use Yii;
    use yii\db\ActiveRecord;
    
    /**
     * This is the model class for table "send_act".
     *
     * @property integer $id
     * @property integer $num
     * @property string $message
     */
    class SendAct extends ActiveRecord
    {
        /**
         * @inheritdoc
         */
        public static function tableName()
        {
            return 'send_act';
        }
    
        /**
         * @inheritdoc
         */
        public function rules()
        {
            return [
                [['num', 'message'], 'required'],
                [['message'], 'string', 'max' => [255]],
            ];
        }
    
        /**
         * @inheritdoc
         */
        public function attributeLabels()
        {
            return [
                'num' => 'Worker ID',
                'message' => 'Text',
            ];
        }
    
        public static function addAct($num, $message)
        {
            $model = new SendAct();
            $model->num = $num;
            $model->message = $message;
            $model->save();
        }        
        
    }

Как создать addAct для создания новой записи. Там просто еще будет логика по обработке данных, потом еще поля добавятся.


Ответы (0 шт):