Notice: Undefined offset: 8192 in /home/miphpf/domains/miphpf.com/public_html/includes/common.inc on line 499

Notice: Undefined offset: 8192 in /home/miphpf/domains/miphpf.com/public_html/includes/common.inc on line 506

Warning: Incorrect key file for table './miphpf_miphpfcom/watchdog.MYI'; try to repair it query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', 'preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/miphpf/domains/miphpf.com/public_html/includes/unicode.inc on line 291.', 2, '', 'http://www.miphpf.com/manual/data_manager.html', '', '18.97.14.88', 1733226048) in /home/miphpf/domains/miphpf.com/public_html/includes/database.mysql.inc on line 121
Data Manager | MIPHPF - Your Open Source RAD PHP Framework
Skip navigation.
Home

Data Manager

: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/miphpf/domains/miphpf.com/public_html/includes/unicode.inc on line 291.

Data Manager is a base class for a CRUD or a listing page. CRUD stand for Create, Retrieve, Update, Delete. In other words by subclassing Data Manager any kind of management screen can be easily created.

To set up a data manager derive the base class (miDataManager) and map the page templates and form fields. Create a object of this class and pass it to the newly created page object.

When a data manager object is created, it initializes the table, and the form object through initTable() and initWebForm() methods. When they are initialized, action handling mechanism is invoked - action object is created, and its doAction() method is called.
The action object processes the request and displays the page.

Basic actions are provided by the framework to create, edit , view, list, and delete data.
Creation: miCreate and miExecCreate classes
Editing: miEdit and miExecEdit classes
View: miViewAction class
Delete: miExecDelete class
Listing: miListAction class

Description how to implement various common situations follows:
1. Specify own domain object
Domain object is created within the method createDomainObject(). Overriding this method allows creation of specific domain objects.
* Example

<?php
class UserDataManager extends miDataManager
{
   
// Set the templates location
   
protected $_templates = array(
       
self::TEMPLATE_ID_CREATE => 'public/user/user_create.tmpl'
   
);
   
   
// Map the page fields
   
protected $_dataFields = array(
        array(
           
'field' => 'miWebFormWidgetText',
           
'data' => 'UserLogin',
        ),
        array(
           
'field' => 'WebFormWidgetCreatePassword',    // Use custom widget class
           
'data' => 'UserPassword',
        )
    );
       
   
protected function createDomainObject()
    {
       
// Get the miRecord object from the data manager
       
$record = new miSqlRecord('Users', 'UserID');
       
// Just create the custom domain object and return the control to the data manager
       
return new UserCreateDomainObject($record);
    }
}
?>

Note: It is recommended that domain objects are created through factory class.
2. Customize table
To initialize the table, when listing records, override the initTable() method.
* Example
<?php
class UserDataManager extends miDataManager
{
   
// Set the templates location
   
protected $_templates = array(
       
self::TEMPLATE_ID_CREATE => 'public/user/user_create.tmpl'
   
);
   
   
// Map the page fields
   
protected $_dataFields = array(
        array(
           
'field' => 'miWebFormWidgetText',
           
'data' => 'UserLogin',
        ),
        array(
           
'field' => 'WebFormWidgetCreatePassword',    // Use custom widget class
           
'data' => 'UserPassword',
        )
    );
   
   
public function initTable(miTable $table)
    {
       
// Initialize the default behaiviour of the table
       
parent::initTable($table);
       
       
// Create table pager with records per page manager
       
$pager = new miTablePager($table);
        new
miTableRecordsPerPage($table, $pager);
    }
}
?>
3. Customize create / edit form
Like for tables, there is a function initWebForm() which initializes the miWebForm object. Functionality can be changed for create / edit forms through overriding this method.
* Example
<?php
class UserDataManager extends miDataManager
{
   
// Set the templates location
   
protected $_templates = array(
       
self::TEMPLATE_ID_CREATE => 'public/user/user_create.tmpl'
   
);
   
   
// Map the page fields
   
protected $_dataFields = array(
        array(
           
'field' => 'miWebFormWidgetText',
           
'data' => 'UserLogin',
        ),
        array(
           
'field' => 'WebFormWidgetCreatePassword',    // Use custom widget class
           
'data' => 'UserPassword',
        )
    );
   
   
public function initWebForm(miWebForm $form)
    {
       
parent::initWebForm($form);
       
       
$productOptions = miUtil::getDBArray('SELECT ProductOptionID, ProductOptionName FROM ProductOptions', 'ProductOptionID', 'ProductOptionName');
       
       
$productOptionsSelect = new miWebFormWidgetSelect($form);
       
$productOptionsSelect->setFieldName('ProductOptions');
       
$productOptionsSelect->setOptions($productOptions);
       
       
$form->addMainPageElements(array('%%PRODUCTOPTIONS%%' => $productOptionsSelect->getEditableControl()));
    }
}
?>
4. Pre-process and post-process
Preprocessing, or post processing is performed by preProcess() and postProcess() methods. These two function can be reimplemented to change the default behavior.
* Example
<?php
class UserDataManager extends miDataManager
{
   
protected function preProcess($actionObj)
    {
       
// $actionObj is the action object
        // Here goes the specific code ...
   
}
   
   
protected function postProcess($actionObj, $actionResult)
    {
       
// $actionObj is the action object
        // $actionResult is the result of the action processing
        // Here goes the specific code ...
   
}
}
?>