Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.43 KB | None | 0 0
  1. //controller
  2. <?php
  3. public function add()
  4.     {
  5.         $this->loadModel('DogsCats');
  6.  
  7.         $dogsUnmated = $this->DogsCats->Dogs->find('list')->notMatching('DogsCats');
  8.         $this->set('dogsUnmated', $dogsUnmated);
  9.  
  10.         $catsUnmated = $this->DogsCats->Cats->find('list')->notMatching('DogsCats');
  11.         $this->set('catsUnmated', $catsUnmated);
  12.  
  13.         //real addition
  14.  
  15.         $farms = $this->DogsCats->newEntity();
  16.         if ($this->request->is('post')) {
  17.             $farms = $this->DogsCats->patchEntity($farms, $this->request->getData());
  18.  
  19.             if ($this->DogsCats->save($farms)) {
  20.                 $this->Flash->success(__('Hai aggiunto il tuo cane con il gatto.',['key'=>'message']));
  21.                 return $this->redirect(['action' => 'index']);
  22.             }
  23.             $this->Flash->error(__('Unable to add your allenatore.'));
  24.         }
  25.         $this->set('farms', $farms);
  26.    
  27.     }
  28.  
  29. //add.ctp
  30. <?php echo $this->Html->script(['single']); ?>
  31. <?php echo $this->Form->create($farms); ?>  
  32. <fieldset>
  33.      <h1>Aggiungi cani e gatti</h1>
  34.  
  35.     <div class="form-group">
  36.         <div class="col-lg-10 col-lg-offset-2">
  37.         <?php
  38.         //how can I make the value field dynamic? avoiding that I always overwrite the data with id 1
  39.         echo $this->Form->control('id', ['type' => 'hidden', 'value' => 1]);  ?>      
  40.         </div>  
  41.     </div>
  42.     <div class="form-group">
  43.         <div class="col-lg-10 col-lg-offset-2">
  44.          <label for="info">Dog</label>
  45.          <?php echo $this->Form->select('dog_id', $dogsUnmated,['class'=>'form-control','required' => true]);?>  
  46.         </div>  
  47.     </div>
  48.     <div class="form-group">
  49.         <div class="col-lg-10 col-lg-offset-2">
  50.         <label for="info">Cat</label>
  51.         <?php echo $this->Form->select('dog_id', $catsUnmated,['class'=>'form-control','required' => true]);?>    
  52.         </div>  
  53.     </div>
  54.     <div class="form-group">
  55.         <div class="col-lg-10 col-lg-offset-2">
  56.          <?php echo $this->Form->control('info',['class'=>'form-control','required' => true]);?>  
  57.         </div>  
  58.     </div>
  59.     <div class="form-group">
  60.         <div class="col-lg-10 col-lg-offset-2">
  61.          <?php echo $this->Form->button(__('Save'),['class'=>'btn btn-primary']);?>  
  62.         </div>  
  63.     </div>          
  64. </fieldset>
  65. <?php echo $this->Form->end();?>  
  66. <?php echo $this->Html->link('back', ['action'=>'index'], ['class'=>'btn btn-primary']) ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement