dev-master
9999999-devVerification and extension for Idiorm/Paris
The Requires
by Abdul Rafay Hingoro
1.0.0
1.0.0.0Verification and extension for Idiorm/Paris
The Requires
by Abdul Rafay Hingoro
Verification and extension for Idiorm/Paris
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)
vmodel.php
in your Models Directory extends
like this
php
<?php
class YourModelName extends VModel {
//your code
}
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 } }
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();
Verification and extension for Idiorm/Paris
Verification and extension for Idiorm/Paris