Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. //CouponsController.php
  2. public function addCoupon() {
  3. $coupon = $this->Coupons->newEntity();
  4. if ($this->request->is('post')) {
  5. $coupon = $this->Coupons->patchEntity($coupon, $this->request->data);
  6. if ($this->Coupons->save($coupon)) {
  7. $this->Flash->success(__('The coupon has been saved.'));
  8. return $this->redirect(['action' => 'index']);
  9. } else {
  10. $this->Flash->error(__('The coupon could not be saved. Please, try again.'));
  11. }
  12. }
  13. $coupons = $this->Coupons->Coupons->find('list', ['limit' => 200]);
  14. $this->set(compact('coupon', 'coupons'));
  15. $this->set('_serialize', ['coupon']);
  16. }
  17.  
  18. //CouponsTable.php
  19. public function initialize(array $config)
  20. {
  21. parent::initialize($config);
  22. $this->table('coupons');
  23. $this->displayField('coupon_id');
  24. $this->primaryKey('coupon_id');
  25. $this->belongsTo('Coupons', [
  26. 'foreignKey' => 'coupon_id',
  27. 'joinType' => 'INNER'
  28. ]);
  29. }
  30.  
  31. //add_coupon.ctp
  32. <h3>Add Coupon</h3>
  33. <?php
  34. echo $this->Form->create(null,['url' => ['action' => 'addCoupon']]);
  35. echo $this->Form->input('coupon_code');
  36. echo $this->Form->input('expiration_date');
  37. echo $this->Form->input('discount_amount');
  38. echo $this->Form->input('usage_limit');
  39. echo $this->Form->input('domain_limit');
  40. echo $this->Form->input('description');
  41. echo $this->Form->input('type');
  42. echo $this->Form->button('Submit');
  43. echo $this->Form->end();
  44. ?>
  45.  
  46. $this->Coupons->Coupons->find('list', ['limit' => 200])
  47.  
  48. $this->Coupons->find('list', ['limit' => 200])
  49.  
  50. $this->belongsTo('Coupons', [
  51. 'foreignKey' => 'coupon_id',
  52. 'joinType' => 'INNER'
  53. ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement