PHP Classes

D3 System: Framework to edit model data using CRUD interfaces

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 34 All time: 11,063 This week: 55Up
Version License PHP version Categories
d3system 1.0Freeware5HTML, PHP 5, Databases, Libraries, De...
Description 

Author

This package provides a framework to edit model data using CRUD interfaces.

It provides a structure of classes to implement model classes that store and retrieve data that will be edited by the users on a Web page.

Applications may configure several aspects like:

- The list of model classes that will be available to edit the record data

- Which model fields can be edited using Web forms

- How the data the user entered in forms will be mapped before storing in the database

- Code that will be used to implement custom processing of user data

Picture of Uldis Nelsons
Name: Uldis Nelsons <contact>
Classes: 19 packages by
Country: Latvia Latvia
Innovation award
Innovation award
Nominee: 12x

Winner: 2x

 

Documentation

d3system

Installation

composer require d3yii2/d3system dev-master

Configuration

add translation

$config = [
   'components' => [
        'i18n' => [
            'translations' => [ 
                'd3system*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@d3yii2/d3system/messages',
                    'sourceLanguage' => 'en-US',
                ],
                'crud' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@d3yii2/d3system/messages',
                    'sourceLanguage' => 'en-US',
                ],
            ]
        ]
    ]
];

Components

ModelsList

Configuration:

 'components' => [
        'ModelsList' => [
            'class' => 'd3system\compnents\ModelsList',
            'cacheKey' => 'd3system\modeList',
            'cacheDuration' => 3600
        ]    
        

Usage:

  $modelId = \Yii::$app->ModelsList->getId($model);

Date & Time conversions

Dependency https://github.com/d3yii2/yii2-datetime

Conversion works only for the model attributes suffixed vith "_local" A example, instead

$model->YOUR_ATTRIBUTE

use

$model->YOUR_ATTRIBUTE_local

Add behavior config in model

Add the behavior to your model and list the attributes need to be converted Important: do NOT add the "_local" suffix here!

public function behaviors(): array
{
    return D3DateTimeBehavior::getConfig(['YOUR_ATTRIBUTE']);
}

Or if You need custom options (see the https://github.com/d3yii2/yii2-datetime)

public function behaviors()
{
    return [
        'datetime' => [
            'class' => D3DateTimeBehavior::className(), // Our behavior
            'attributes' => [
                'YOUR_ATTRIBUTE', // List all editable date/time attributes
            ],
            // Date formats or other options
           'originalFormat' => ['datetime', 'yyyy-MM-dd HH:mm:ss'],
           'targetFormat' => 'date',
        ]
    ];
}

Display value in view

<?= $model->YOUR_ATTRIBUTE_local ?>

Assign the value before save

$model->load(Yii::$app->request->post());

or

 $model->YOUR_ATTRIBUTE_local = $value;

or

 $model->setAttribute('YOUR_ATTRIBUTE_local', $value);

By multiple assignment via load() ensure the local attributes have 'safe' rules:

// Virtual params for DateTimeBehavior
public function rules(): array
{   
    return [
        [...],
        [['YOUR_ATTRIBUTE_local'], 'safe'],
    ];
}

D3EditableAction Initial Setup in Controller

editAbleFields: must match real attributes
editAbleFieldsForbbiden: must match real attributes
modelName: pass current controller model Name with full Namespace
/
 * @var array
 */
public $editAbleFields = ['hasEditable', 'status'];

/
 * @var array
 */
public $editAbleFieldsForbbiden = [];

Actions

public function actions()
{
    return [
        'editable'      => [
            'class'                   => D3EditableAction::class,
             'modelName'               => AudAuditor::class,
             'editAbleFields'          => ['status','notes'],
             'editAbleFieldsForbbiden' => $this->editAbleFieldsForbbiden,
             'preProcess' => static function (Inout $model) {
                  if ($model->isAttributeChanged('driver')) {
                     $model->driver = iconv('UTF-8', 'ASCII//TRANSLIT',$model->driver);
                  }   
             },
             'outPreProcess' => static function (ContInout $model, array $output) {
                 if (isset($output['ediBookingId'])) {
                     $output['ediBookingId'] = DepoEdiBookingDictionary::getIdLabel($output['ediBookingId']);
                 }
                 return $output;
             }             
        ],
    ];
}


  Files folder image Files (49)  
File Role Description
Files folder imageactions (4 files)
Files folder imagebehaviors (1 file)
Files folder imagecommands (1 file)
Files folder imagecompnents (4 files, 1 directory)
Files folder imagedictionaries (1 file)
Files folder imageexceptions (3 files)
Files folder imagegii (1 file)
Files folder imagehelpers (1 file)
Files folder imagemessages (2 directories)
Files folder imagemigrations (4 files)
Files folder imagemodels (5 files, 1 directory)
Files folder imageviews (1 directory)
Files folder imagewidgets (3 files)
Files folder imageyii2 (5 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Plain text file Module.php Class Class source
Accessible without login Plain text file README.md Doc. Read me

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:34
This week:0
All time:11,063
This week:55Up