Those are three concepts on Yii that I really don't get what should we use, on what scenarios?
Can anyone be kind enough to clarify those Yii elements, and on what situation should we use them?
Those are three concepts on Yii that I really don't get what should we use, on what scenarios?
Can anyone be kind enough to clarify those Yii elements, and on what situation should we use them?
Check here for live examples of ActiveForm, CForm, et cetera. You can also see the live Model, View & Controller files.
In documentation of CForm one can read the following:
...and
CActiveForm
represents the latter.In other words,
CForm
specifies elements of the form butCActiveForm
(being a widget) renders it.Looking at the source code we state that
CForm
can also render() itself and its rendering relies on and is wrapped byCActiveForm
widget by introducing its configuration property activeForm, though rendering input elements and buttons is implemented by its own methods renderElements() and renderButtons() relatively. By default their implementations rely on classes using CHtml's static methods what is exactly the same (or almost exactly the same) whatCActiveForm
's rendering methods do. Of course, default behavior can be overriden by extending the class.That's why it's the question of a taste which technique to use:
CActiveForm
widget alone combining form fields' and buttons' declaration with their representation in a view file by calling convenient (required) methods ofCActiveForm
instance orCForm
class declaring form's input specifications in a separate configuration file and customizing its rendering by pointing at appropriate active form widget and/or by overriding default rendering methods. The latter technique allows to reuse a form in several actions easily and is no more than using form builder.