Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //controller
- <?php
- public function add()
- {
- $this->loadModel('DogsCats');
- $dogsUnmated = $this->DogsCats->Dogs->find('list')->notMatching('DogsCats');
- $this->set('dogsUnmated', $dogsUnmated);
- $catsUnmated = $this->DogsCats->Cats->find('list')->notMatching('DogsCats');
- $this->set('catsUnmated', $catsUnmated);
- //real addition
- $farms = $this->DogsCats->newEntity();
- if ($this->request->is('post')) {
- $farms = $this->DogsCats->patchEntity($farms, $this->request->getData());
- if ($this->DogsCats->save($farms)) {
- $this->Flash->success(__('Hai aggiunto il tuo cane con il gatto.',['key'=>'message']));
- return $this->redirect(['action' => 'index']);
- }
- $this->Flash->error(__('Unable to add your allenatore.'));
- }
- $this->set('farms', $farms);
- }
- //add.ctp
- <?php echo $this->Html->script(['single']); ?>
- <?php echo $this->Form->create($farms); ?>
- <fieldset>
- <h1>Aggiungi cani e gatti</h1>
- <div class="form-group">
- <div class="col-lg-10 col-lg-offset-2">
- <?php
- //how can I make the value field dynamic? avoiding that I always overwrite the data with id 1
- echo $this->Form->control('id', ['type' => 'hidden', 'value' => 1]); ?>
- </div>
- </div>
- <div class="form-group">
- <div class="col-lg-10 col-lg-offset-2">
- <label for="info">Dog</label>
- <?php echo $this->Form->select('dog_id', $dogsUnmated,['class'=>'form-control','required' => true]);?>
- </div>
- </div>
- <div class="form-group">
- <div class="col-lg-10 col-lg-offset-2">
- <label for="info">Cat</label>
- <?php echo $this->Form->select('dog_id', $catsUnmated,['class'=>'form-control','required' => true]);?>
- </div>
- </div>
- <div class="form-group">
- <div class="col-lg-10 col-lg-offset-2">
- <?php echo $this->Form->control('info',['class'=>'form-control','required' => true]);?>
- </div>
- </div>
- <div class="form-group">
- <div class="col-lg-10 col-lg-offset-2">
- <?php echo $this->Form->button(__('Save'),['class'=>'btn btn-primary']);?>
- </div>
- </div>
- </fieldset>
- <?php echo $this->Form->end();?>
- <?php echo $this->Html->link('back', ['action'=>'index'], ['class'=>'btn btn-primary']) ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement