|
Db_FormBehavior class
Adds form handling features to back-end controllers.
This class allows to extend any back-end controller with a form handling functionality.
It allows to render Create, Edit and Preview forms along with processing corresponding
AJAX events for saving and deleting records.
The extension can be added to a controller by listing the class name in the $implement property of the controller class: class AbcBlog_Posts extends Backend_Controller { public $implement = 'Db_FormBehavior, Db_ListBehavior'; ... To configure the extension, its properties should be defined in the extended controller class. Only the $form_model_class property is required. Please read the Administration Area Forms article for the usage examples and details. Public properties
Public methods
Events
Property details¶ form_create_save_flash propertypublic string $form_create_save_flash;
A message to display after a new record has been successfully saved.
¶ form_create_save_redirect propertypublic string $form_create_save_redirect;
An URL to redirect the browser after the Create form is successfully processed.
This value overrides the $form_redirect property.
¶ form_create_title propertypublic string $form_create_title;
Specifies a title of the Create Record page.
The default value is Create.
¶ form_delete_redirect propertypublic string $form_delete_redirect;
An URL to redirect the browser after a record has been deleted.
This value overrides the $form_redirect
and $form_edit_save_redirect properties.
¶ form_edit_delete_flash propertypublic string $form_edit_delete_flash;
A message to display after a record has been successfully deleted.
¶ form_edit_save_flash propertypublic string $form_edit_save_flash;
A message to display after an existing record has been successfully saved.
¶ form_edit_save_redirect propertypublic string $form_edit_save_redirect;
An URL to redirect the browser after the Save form is successfully processed.
This value overrides the $form_redirect property.
¶ form_edit_title propertypublic string $form_edit_title;
Specifies a title of the Edit Record page.
The default value is Edit.
¶ form_model_class propertypublic string $form_model_class;
A name of the model class.
¶ form_not_found_message propertypublic string $form_not_found_message;
Message to display on the Edit and Preview pages in case if the record is not found.
The default value is "Record not found".
¶ form_preview_title propertypublic string $form_preview_title;
Specifies a title of the Preview Record page.
The default value is Preview.
¶ form_redirect propertypublic string $form_redirect;
An URL to redirect the browser after a form is saved or the record is deleted.
Use the url() for creating back-end URLs. Example:
$this->form_redirect = url('/shop/product_types'); Method details¶ formAfterCreateSave() methodpublic void formAfterCreateSave(Db_ActiveRecord $model, string $session_key)
Called after a new record is saved to the database.
This method can be overridden in the controller and used as an event handler.
¶ formAfterDelete() methodpublic void formAfterDelete(Db_ActiveRecord $model, string $session_key)
Called after a record is deleted from the database.
This method can be overridden in the controller and used as an event handler.
¶ formAfterEditSave() methodpublic void formAfterEditSave(Db_ActiveRecord $model, string $session_key)
Called after an existing record is saved to the database.
This method can be overridden in the controller and used as an event handler.
¶ formAfterSave() methodpublic void formAfterSave(Db_ActiveRecord $model, string $session_key)
Called after a new or existing record is saved to the database.
This method can be overridden in the controller and used as an event handler.
¶ formBeforeCreateSave() methodpublic void formBeforeCreateSave(Db_ActiveRecord $model, string $session_key)
Called before a new record is saved to the database.
This method can be overridden in the controller and used as an event handler.
¶ formBeforeEditSave() methodpublic void formBeforeEditSave(Db_ActiveRecord $model, string $session_key)
Called before an existing record is saved to the database.
This method can be overridden in the controller and used as an event handler.
¶ formBeforeSave() methodpublic void formBeforeSave(Db_ActiveRecord $model, string $session_key)
Called before a new or existing record is saved to the database.
This method can be overridden in the controller and used as an event handler.
¶ formCreateModelObject() methodpublic Db_ActiveRecord formCreateModelObject()
Creates the form model object for the Create page.
This method can be overridden in the controller class if a special
actions should be performed in order to create the model. By default
the method creates an object of class specified in the $form_model_class property.
¶ formFindModelObject() methodpublic Db_ActiveRecord formFindModelObject(integer $record_id)
Finds a model object for the Edit page.
This method can be overridden in the controller class if a special
actions should be performed in order to load a model from the database. By default
the method creates an object of class specified in the $form_model_class property
and then finds a record by the primary key value specified in the page URL.
¶ formRender() methodpublic void formRender(Db_ActiveRecord $model=NULL)
Renders the form.
This method should be called on the Create or Edit pages. The FORM element and buttons should be defined
separately. The buttons should trigger events with names corresponding the action name - create_onSave, edit_onSave, etc.
The event handlers are defined in the extension class.
Example of the Create form:
<?= Phpr_Form::openTag() ?> <? $this->formRender() ?> <?= backend_ajax_button('Create', 'create_onSave', array('class'=>'default')) ?> <?= backend_ajax_button('Cancel', 'create_onCancel') ?> </form> <?= Phpr_Form::openTag(array('id'=>'form_element')) ?> <? $this->formRender() ?> <?= backend_ajax_button('Save', 'edit_onSave', array('class'=>'default')) ?> <?= backend_ajax_button('Cancel', 'edit_onCancel') ?> <?= backend_ajax_button('Delete', 'edit_onDelete', array('class'=>"right"), "confirm: 'Do you really want to delete this record?'") ?> <div class="clear"></div> </form> ¶ formRenderPreview() methodpublic void formRenderPreview(Db_ActiveRecord $model=NULL)
Renders the form in Preview (read-only) mode.
This method should be called on the Preview page. Example:
<? $this->formRenderPreview() ?> |