Tuesday, September 1, 2009

INTEGRATING THE DIG_FORM WITH MODELS

I was just working with some comments and saw a familiar pattern for updating a model:
  1. Get the values from the form.
  2. Create an instance of the model.
  3. Populate and save model.
I added a method to the Dig_Form class that should make this easier;  getValuesAsModel(). You pass this method the class name of a model, and creates an instance and loads it for you.

$modelPost = $formPost->getValuesAsModel('Blog_Model_Post');

I added a second convenience method to this, saveToModel(), which you pass the name of a model to. It fetches the model (using the getValuesAsModel method) and saves it.

No comments:

Post a Comment