I have a form, where users pick some options, and I would like to insert into DB an additional, concatenated field, based on user inputs. I need to do it on SCENARIO_CREATE (and update). E.g.:
type: A
size: 100
color: black
concatenated: A100black
I've tried it this way:
Model:
class Xyz extends BaseXyz {
const SCENARIO_CREATE = 'create';
public function rules() {
...
['concatenated', 'generateConcatenated', 'on' => self::SCENARIO_CREATE],
...
public function generateConcatenated() {
return $this->type . $this->size . $this->color;
}
Controller:
class XyzController extends base\XyzController {
public function actionCreate() {
$model = new Xyz;
$model->scenario = Xyz::SCENARIO_CREATE;
...
I've tried with 'filter'
also in rules, but no success. Maybe my approach is totally wrong, and it can't be done in rules? Please point me in the right direction. Many thanks!