PHP code example of rafayhingoro / vmodel-idiorm-extension

1. Go to this page and download the library: Download rafayhingoro/vmodel-idiorm-extension library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rafayhingoro / vmodel-idiorm-extension example snippets


     
     class YourModelName extends VModel {
       //your code 
     }
   
 
    
    class YourModelName extends VModel {
        public $_isValid = true; //by default making it valid
        
        //fields which are in database
        public $_fields = array(
            'id',
            'name',
            'email',
            'contact_number',
            'description'
        );
        
        //adding rules for fields 
        protected $_rules = array(
            'category_id' => '

     
    class ControllerUser {
         try {
         
            // $form is array of inputs here's an example 
            // $form['username'] = 'user1234';
            // $form['password'] = 'mySecretPassword';
            // $form['email'] = '[email protected]';
            // ... 
           
             $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 
         }
     }
   

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' => '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();