M
M
McMike2016-12-13 08:26:52
Yii
McMike, 2016-12-13 08:26:52

How can I make the attribute populated but optional?

I'm trying to edit a model from a form.
There is an id field. If I specify it in the rules, then editing is fine, the model is filled from the post.
But at the same time, an error occurs during creation - it tries to write null in the id field, and it should be automatically filled in the database.
If I remove the id from the rules, it is created normally, but when editing it is not filled from the array.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2016-12-13
@McMike

In situations where it is worth filling in attributes in one case and not in the other, it is worth using scripts and safe attributes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question