2017 © Pedro Peláez
 

library vmodel-idiorm-extension

Verification and extension for Idiorm/Paris

image

rafayhingoro/vmodel-idiorm-extension

Verification and extension for Idiorm/Paris

  • Wednesday, March 29, 2017
  • by rafayhingoro
  • Repository
  • 1 Watchers
  • 1 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

VModel - Idiorm/Paris Extension

https://github.com/rafayhingoro/vmodel-idiorm-extension, (*1)


Built on top of Idiorm & Paris., (*2)

Tested on PHP 5.4.0+ - may work on earlier versions with PDO and the correct database drivers., (*3)

Released under a MIT license., (*4)

Documentation

# Setup Guide

  1. Download release source code and move vmodel.php in your Models Directory
  2. on any model where you want to use vmodel simply use extends like this php <?php class YourModelName extends VModel { //your code }
  3. for validating before save Model File YourModelName.php, (*5)

     'required',
            'name' => 'required',
            'email' => 'required|email',
            'contact_number' => 'required',
            'description' => 'required'
        );
    }
    ?>
    

    Controller File ControllerUser.php, (*6)

    <?php 
    class ControllerUser {
         try {
    
            // $form is array of inputs here's an example 
            // $form['username'] = 'user1234';
            // $form['password'] = 'mySecretPassword';
            // $form['email'] = 'myemail@123.com';
            // ... 
    
             $oModel = Model::factory("YourModelName")->create();
             $oModel->validateForm($form); //throws exception if form is not valid
             ...
         } catch (Exception $ex) {
            $ex->getMessage(); //validation error will be available here 
         }
     }
    

Validation Modal

class Item extends VModel {
    public $_fields = array(
        'id',
        'shop_id',
        'cat_id',
        'name',
        'description',
        'price',
        'created_on',
        'created_by',
        'updated_by',
        'updated_on'
    );
    public $_rules = array(
        'shop_id' => 'required',
        'cat_id'     => 'required|int',
        'name'       => 'required',
        'description' => 'required|limit<500',
        'price'       => 'required|int'
    );
}
$form = array(
    'shop_id' => 23,
    'cat_id' => 12,
    'name' => 'XYZ product',
    'description' => 'some description ...',
    'price' => '12.00'
);

$item = Model::factory('Item')
         ->saveForm($form);
//or
$item = Model::factory('Item')
         ->validateForm($form);
 $item->shop_id = $form['shop_id'];
 $item->cat_id = $form['cat_id'];
 $item->name = $form['name'];
 $item->description = $form['description'];
 $item->price = $form['price'];
 $item->save();

1.0.0 - released 2017-03-19

  • Initial release

The Versions

29/03 2017

dev-master

9999999-dev

Verification and extension for Idiorm/Paris

  Sources   Download

The Requires

 

by Abdul Rafay Hingoro

19/03 2017

1.0.0

1.0.0.0

Verification and extension for Idiorm/Paris

  Sources   Download

The Requires

 

by Abdul Rafay Hingoro