0
votes

When i call my create action i got the followinf error :

Exception (Invalid Configuration) 'yii\base\InvalidConfigException' with message 'Invalid validation rule: a rule must specify both attribute names and validator type.'

That's my controllers' action:

public function actionCreate()
    {
        $model = new Message();

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }

And my rules function :

public function rules()
    {
        return [
            [['sender_id', 'receiver_id', 'text'], 'required'],
            [['sender_id', 'receiver_id', 'last_message', 'is_new', 'is_deleted_by_sender', 'is_deleted_by_receiver'], 'integer'],
            [['created_at'], 'safe'],
            [['text'], 'string', 'max' => 100],
            [['receiver_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['receiver_id' => 'id']],
            [['sender_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['sender_id' => 'id']],
            [['admin/message/chat/idUser/<id:\d+>' => 'admin/message/chat']],
        ];
    }
1

1 Answers

0
votes

This

[['admin/message/chat/idUser/<id:\d+>' => 'admin/message/chat']],

is UrlManager rule, not validation rule - it should be in UrlManager configuration.