Model-Based Forms

In Agile Toolkit models are used to describe business entities. Controllers allow to build integration between Model and View, such as Form.

class Model_Employee extends Model_Person {
    function 
defineFields(){
        
parent::defineFields();

        
$this->addField('name')
            ->
mandatory(true);

        
$this->addField('days_worked')
            ->
system(true)
            ->
datatype('int');

        
$this->addField('salary')
            ->
mandatory(true)
            ->
datatype('money');

        
$this->addField('money_owed')
            ->
caption('Owed')
            ->
calculated(true);
    }
}

Building form from Model

To use Model functionality you would need to use MVCForm instead of Form. Calling setModel() or setController() will initialize form by adding fields and binding it with the model.

It's recommended to use setModel(), which will use default controller for integration between Form and Model.

Sometimes it is required to omit some fields from the form, or change field order. This can be done through 2nd argument to setModel.

Using existing Model

Instead of specifying name of the model, you can create the model object and specify exstinging model as a first argument.

This time I have added more code to make form more usable and to actually capture saved data and insert them into the database. addCondition() allowed me to modify model on the fly.