· 6 years ago · Dec 17, 2019, 02:24 PM
1CREATE TABLE IF NOT EXISTS trainers (
2 id int(11) NOT NULL,
3 name varchar(40) NOT NULL,
4 surname varchar(40) NOT NULL
5) ENGINE=InnoDB DEFAULT CHARSET=utf8;
6
7CREATE TABLE IF NOT EXISTS clubs (
8 id int(11) NOT NULL,
9 name varchar(40) NOT NULL,
10 info varchar(40) NOT NULL
11) ENGINE=InnoDB DEFAULT CHARSET=utf8;
12
13CREATE TABLE IF NOT EXISTS seasons_trainers (
14 id int(11) NOT NULL,
15 trainer_id int(11) NOT NULL,
16 club_id int(11) NOT NULL,
17 info varchar(40) NOT NULL
18) ENGINE=InnoDB DEFAULT CHARSET=utf8;
19
20ALTER TABLE trainers
21ADD PRIMARY KEY (id),
22MODIFY id int(11) NOT NULL AUTO_INCREMENT;
23
24ALTER TABLE clubs
25ADD PRIMARY KEY (id),
26MODIFY id int(11) NOT NULL AUTO_INCREMENT;
27
28ALTER TABLE seasons_trainers
29ADD PRIMARY KEY (id),
30MODIFY id int(11) NOT NULL AUTO_INCREMENT,
31ADD FOREIGN KEY(trainer_id) REFERENCES trainers(id),
32ADD FOREIGN KEY(club_id) REFERENCES clubs(id);
33
34
35in controller SeasonsTrainersController
36
37 /**
38 * Add method
39 *
40 * @return \Cake\Http\Response|null Redirects on successful add, renders view otherwise.
41 */
42 public function add()
43 {
44 //$trainers = $this->SeasonTrainers->Trainers->find('list', ['limit' => 200]);
45 $trainersUnmated=$this->SeasonTrainers->Trainers->find('list')->notMatching('SeasonTrainers');
46
47 //$clubs = $this->SeasonTrainers->Clubs->find('list', ['limit' => 200]);
48 $clubsUnmated=$this->SeasonTrainers->Clubs->find('list')->notMatching('SeasonTrainers');
49
50 $seasonTrainer = $this->SeasonTrainers->newEntity();
51 if ($this->request->is('post')) {
52 $seasonTrainer = $this->SeasonTrainers->patchEntity($seasonTrainer, $this->request->getData());
53 if ($this->SeasonTrainers->save($seasonTrainer)) {
54 $this->Flash->success(__('The season trainer has been saved.'));
55
56 return $this->redirect(['action' => 'index']);
57 }
58 $this->Flash->error(__('The season trainer could not be saved. Please, try again.'));
59 }
60
61
62
63 $this->set(compact('seasonTrainer', 'trainersUnmated', 'clubsUnmated'));
64 }
65
66add.ctp
67
68<?php
69/**
70 * @var \App\View\AppView $this
71 * @var \App\Model\Entity\SeasonTrainer $seasonTrainer
72 */
73?>
74<nav class="large-3 medium-4 columns" id="actions-sidebar">
75 <ul class="side-nav">
76 <li class="heading"><?= __('Actions') ?></li>
77 <li><?= $this->Html->link(__('List Season Trainers'), ['action' => 'index']) ?></li>
78 <li><?= $this->Html->link(__('List Trainers'), ['controller' => 'Trainers', 'action' => 'index']) ?></li>
79 <li><?= $this->Html->link(__('New Trainer'), ['controller' => 'Trainers', 'action' => 'add']) ?></li>
80 <li><?= $this->Html->link(__('List Clubs'), ['controller' => 'Clubs', 'action' => 'index']) ?></li>
81 <li><?= $this->Html->link(__('New Club'), ['controller' => 'Clubs', 'action' => 'add']) ?></li>
82 </ul>
83</nav>
84<div class="seasonTrainers form large-9 medium-8 columns content">
85 <?= $this->Form->create($seasonTrainer) ?>
86 <fieldset>
87 <legend><?= __('Add Season Trainer') ?></legend>
88 <?php
89 echo $this->Form->control('trainer_id', ['options' => $trainersUnmated]);
90 echo $this->Form->control('club_id', ['options' => $clubsUnmated]);
91 echo $this->Form->control('anno');
92 echo $this->Form->control('season');
93 echo $this->Form->control('SERIE');
94 echo $this->Form->control('POS');
95 echo $this->Form->control('CLASS');
96 echo $this->Form->control('VN');
97 echo $this->Form->control('NU');
98 echo $this->Form->control('PE');
99 echo $this->Form->control('GF');
100 echo $this->Form->control('GS');
101 ?>
102 </fieldset>
103 <?= $this->Form->button(__('Submit')) ?>
104 <?= $this->Form->end() ?>
105</div>