daily pastebin goal
5%
SHARE
TWEET

Untitled

a guest Oct 15th, 2018 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. include "vendor/autoload.php"; // it is crap, I will explain it later.
  3. include "dao/ProductDao2.php";
  4. // view
  5. $blade=new \eftec\bladeone\BladeOne(__DIR__."/view",__DIR__."/compile");
  6. $blade->setMode(\eftec\bladeone\BladeOne::MODE_DEBUG);
  7.  
  8. // validation
  9. $val=new \eftec\ValidationOne();
  10.  
  11. // persistence
  12. $db=new \eftec\DaoOne("localhost","root","abc.123","bladeonetut1");
  13. try {
  14.     $db->connect();
  15. } catch (Exception $e) {
  16.     $val->addMessage("general","Database is down :".$e->getMessage(),'error');
  17. }
  18.  
  19.  
  20. // this page is two stage:
  21. // stage one, the form is open as new
  22. // stage two, the form was open and somebody clicked on the button
  23.  
  24. // collecting information
  25.  
  26.  
  27. $button=$val
  28.     ->type('integer') // it must be a number
  29.     ->def(0) // default value is zero
  30.     ->ifFailThenDefault() // if fails then, the button will be the default value=0
  31.     ->post('frm_button'); // fetch the value
  32. if ($button) {
  33.     $product['name']=$val
  34.         ->type('string') // it could be anything.
  35.         ->required() // required is only if the fetch fails, not if the text is empty or not
  36.         ->condition('betweenlen','',[4,40]) // the length must be between 4 and 40 characters
  37.         ->post('frm_name');
  38.     $product['price']=$val
  39.         ->type('integer') // it must be a number
  40.         ->required() // the field is required (post), again, it's not if the value is zero or not.
  41.         ->condition('between','',[0,10000]) // the value must be between 0 and 10000.
  42.         ->post('frm_price');
  43.     if ($val->messageList->errorcount===0) {
  44.         // we only insert if the number of errors is zero.
  45.         try {
  46.             $product['idproduct'] = \BladeOneTut1\ProductDao::insert($product);
  47.             //we redirect to the list.
  48.             header("location:list2.php");
  49.             die(1);
  50.         } catch (Exception $e) {
  51.             $val->addMessage("general", "Unable to insert the product " . $e->getMessage(), 'error');
  52.         }
  53.     }
  54. } else {
  55.     $product['name']='';
  56.     $product['price']='';
  57. }
  58. echo $blade->run("product.insert4",['product'=>$product,'messages'=>$val->messageList]);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top