Yii2 从我的角度调用另一个动作
Yii2 call another action from my view
当我调用我的创建操作时,出现以下错误:
异常(无效配置)'yii\base\InvalidConfigException' 消息 'Invalid validation rule: a rule must specify both attribute names and validator type.'
这是我的控制器的操作:
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,
]);
}
}
我的规则函数:
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']],
];
}
这个
[['admin/message/chat/idUser/<id:\d+>' => 'admin/message/chat']],
是 UrlManager 规则,不是验证规则 - 它应该在 UrlManager 配置中。
当我调用我的创建操作时,出现以下错误:
异常(无效配置)'yii\base\InvalidConfigException' 消息 'Invalid validation rule: a rule must specify both attribute names and validator type.'
这是我的控制器的操作:
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,
]);
}
}
我的规则函数:
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']],
];
}
这个
[['admin/message/chat/idUser/<id:\d+>' => 'admin/message/chat']],
是 UrlManager 规则,不是验证规则 - 它应该在 UrlManager 配置中。