daily pastebin goal
67%
SHARE
TWEET

Untitled

a guest Feb 21st, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // create new model : param1 - model table , param2 : primary model key
  2. // (default : null)
  3. /*
  4.     $task = new Task("tasks","id");
  5. */
  6.  
  7. // set task vars
  8. /*
  9.     $task->title = "abc";
  10.     $task->pos = 2;
  11. */
  12.  
  13. // get task vars
  14. /*
  15.     $task->title;
  16. */
  17.  
  18. // fetch record data from database to the model object : param1 - value of primary key to search
  19. /*
  20.     $task->fetch(13);
  21. */
  22.  
  23. // update model data
  24. /*
  25.     $task->title = "new title";
  26.     $task->content = "new !!!";
  27.     $task->save(); // will update database record
  28. */
  29.  
  30. // delete database record of a model
  31. /*
  32.     $task->delete();
  33. */
  34.  
  35. // insert new record
  36. /*
  37.     $task->title = "ada";
  38.     $task->content = "Adasda";
  39.     $task->pos = 5;
  40.     $task->insert(); // will insert new record to tasks table in the database
  41. */
  42.  
  43. // get json string of a model
  44. /*
  45.     $task->toJSON();
  46. */
  47.  
  48. // set model table
  49. /*
  50.     $task->setTable("tasks");
  51. */
  52.  
  53. // set model table primary key
  54. /*
  55.     $task->setPrimary("id");
  56. */
  57.  
  58. // create collection : param1 - Model name , param2 - Model database table , param3 - Primary model key , param4 - create models from db ? (default : false)
  59. /*
  60.     $Tasks = new DirectCollection("Task","tasks","id",true);
  61. */
  62.  
  63. // create models
  64. /*
  65.     $Tasks->create(function($task){
  66.         $task->title = "first";
  67.         $task->pos = 3;
  68.         $task->content = "xx";
  69.         return $task;
  70.     },function($task){
  71.         $task->title = "second";
  72.         $task->pos = 4;
  73.         $task->content = "yy";
  74.         return $task;
  75.     });
  76. */
  77.  
  78. // add model
  79. /*
  80.     $t = new Task();
  81.     $t->title = "some title";
  82.     $t->content = "ada";
  83.     $t->pos = 5;
  84.     $Tasks->add($t);
  85. */
  86.  
  87. // add array of models
  88. /*
  89.     $Tasks->addModels(array($t,$t2,$t3));
  90. */
  91.  
  92. // get model by by primary key
  93. /*
  94.     $Tasks->get(13);
  95. */
  96.  
  97. // get model by index value
  98. /*
  99.     $Tasks->at(1);
  100. */
  101.  
  102. // get all models
  103. /*
  104.     $all = $Tasks->models();
  105. */
  106.  
  107. // loop on models
  108. /*
  109.     $Tasks->each(function($task){
  110.         // code here
  111.     });
  112. */
  113.  
  114. // remove model by attribute (default : primary key)
  115. /*
  116.     $Tasks->remove(13); // $primary_key == 13
  117.     $Tasks->remove("abc","title"); // title == "abc"
  118. */
  119.  
  120. // remove all models
  121. /*
  122.     $Tasks->removeAll();
  123. */
  124.  
  125. // remove model by index value
  126. /*
  127.     $Tasks->removeAt(2);
  128. */
  129.  
  130. // pluck model attribute
  131. /*
  132.     $titles = $Tasks->pluck("title");
  133. */
  134.  
  135. // get json string of all models
  136. /*
  137.     $Tasks->toJSON();
  138. */
  139.  
  140. // filter models by condition
  141. /*
  142.     // for example all tasks that the pos is bigger then 1
  143.     $f = $Tasks->filter(function($task){
  144.         return $task->pos > 1; // if true this model will be in the $f array
  145.     },true); // if you want to get a new collection from the filtered array add true (default : false)
  146. */
  147.  
  148. // count models
  149. /*
  150.     $Tasks->count();
  151. */
  152.  
  153. // get the first model
  154. /*
  155.     $Tasks->first();
  156. */
  157.  
  158. // get the last model
  159. /*
  160.     $Tasks->last();
  161. */
  162.  
  163. // get random model
  164. /*
  165.     $Tasks->rand();
  166. */
  167.  
  168. // grab all data from database table and create models instances
  169. /*
  170.     $Tasks->createAll();
  171. */
  172.  
  173. // fetch method on each model
  174. /*
  175.     $Tasks->fetchAll();
  176. */
  177.  
  178. // save method on each model
  179. /*
  180.     $Tasks->saveAll();
  181. */
  182.  
  183. // insert method on each model
  184. /*
  185.     $Tasks->insertAll();
  186. */
  187.  
  188. // delete method on each model
  189. /*
  190.     $Tasks->deleteAll();
  191. */
  192.  
  193. // sort models : param1 - attribute , param2 - type of sort (default : "ASC",options : "ASC"|"DESC")
  194. /*
  195.     // for example sort tasks by id DESC
  196.     $Tasks->sort("id","DESC");
  197.    
  198.     // for example sort tasks by title ASC
  199.     $Tasks->sort("title");
  200. */
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