Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //CouponsController.php
- public function addCoupon() {
- $coupon = $this->Coupons->newEntity();
- if ($this->request->is('post')) {
- $coupon = $this->Coupons->patchEntity($coupon, $this->request->data);
- if ($this->Coupons->save($coupon)) {
- $this->Flash->success(__('The coupon has been saved.'));
- return $this->redirect(['action' => 'index']);
- } else {
- $this->Flash->error(__('The coupon could not be saved. Please, try again.'));
- }
- }
- $coupons = $this->Coupons->Coupons->find('list', ['limit' => 200]);
- $this->set(compact('coupon', 'coupons'));
- $this->set('_serialize', ['coupon']);
- }
- //CouponsTable.php
- public function initialize(array $config)
- {
- parent::initialize($config);
- $this->table('coupons');
- $this->displayField('coupon_id');
- $this->primaryKey('coupon_id');
- $this->belongsTo('Coupons', [
- 'foreignKey' => 'coupon_id',
- 'joinType' => 'INNER'
- ]);
- }
- //add_coupon.ctp
- <h3>Add Coupon</h3>
- <?php
- echo $this->Form->create(null,['url' => ['action' => 'addCoupon']]);
- echo $this->Form->input('coupon_code');
- echo $this->Form->input('expiration_date');
- echo $this->Form->input('discount_amount');
- echo $this->Form->input('usage_limit');
- echo $this->Form->input('domain_limit');
- echo $this->Form->input('description');
- echo $this->Form->input('type');
- echo $this->Form->button('Submit');
- echo $this->Form->end();
- ?>
- $this->Coupons->Coupons->find('list', ['limit' => 200])
- $this->Coupons->find('list', ['limit' => 200])
- $this->belongsTo('Coupons', [
- 'foreignKey' => 'coupon_id',
- 'joinType' => 'INNER'
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement