Answer the question
In order to leave comments, you need to log in
How to make "in a smart way" processing of request parameters and their transformation?
controller:
foreach( $request as $k => $v ) {
if( in_array( $k, ['limit', 'page' ] ) ) {
continue;
}
if( is_array( $v ) ) {
if( isset($v['type']) ) {
switch($v['type']) {
case "parent":
$criterias[] = new Criterion\ParentLocationId($v['val']);
break;
}
} if( isset( $v['like'] ) ) {
switch( $v['like'] ) {
case 0:
$criterias[] = new Criterion\FullText( $v['val'] );
break;
case 1:
$criterias[] = new Criterion\Field( $v['name'], Criterion\Operator::LIKE, $v['val'] . "%" );
break;
case 2:
$criterias[] = new Criterion\Field( $v['name'], Criterion\Operator::LIKE, "%" . $v['val'] . "%" );
break;
case 3:
$criterias[] = new Criterion\Field( $v['name'], Criterion\Operator::EQ, $v['val'] );
break;
}
} else {
$criterias[] = new Criterion\Field( $k, Criterion\Operator::IN, $v );
}
} else {
$criterias[] = new Criterion\Field( $k, Criterion\Operator::EQ, $v);
}
}
if( count( $criterias ) > 0 ) {
$query->filter = new Criterion\LogicalAnd( $criterias );
}
switch($v['type']) {
case "parent":
$criterias[] = new Criterion\ParentLocationId($v['val']);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question