hi, I want to filter the parameters sent to a particular action, using the validators used in the validation of models, but without using models. To separate this logic to check certain parameters in actions that do not use models. I think that create a ActionFilter make use of validators, but not if I’m reinventing the wheel or there is already a better way.
please someone could give me some advice?
example:
test Controller:
<?php
class TestController extend \yii\web\Controller{
public function actionFoo($p1, $p2)
{
if (!somoValidation($p1) or !someValidation($p2)) {
throw new \yii\web\BadRequestHttpException("error");
}
//action code
}
}
to>
<?php
class TestController extend \yii\web\Controller{
public function behaviors()
{
return [
'validate' => [
'class' => ActionParamsFilter::className(),
'actions' => [
"foo" => [
//somting like model validation
]
],
]
];
}
public function actionFoo($p1, $p2)
{
//action code
}
}