Tabellen:
CREATE TABLE IF NOT EXISTS `cake_field_sizes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`xachse` int(11) NOT NULL,
`yachse` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german1_ci AUTO_INCREMENT=2 ;
CREATE TABLE IF NOT EXISTS `cake_games` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) COLLATE latin1_german1_ci NOT NULL,
`aera_id` int(11) NOT NULL,
`number_player_id` int(11) NOT NULL,
`round_id` int(11) NOT NULL,
`verbleibende_runden` int(11) NOT NULL,
`waiting_time_id` int(11) NOT NULL,
`xachse` int(11) NOT NULL,
`yachse` int(11) NOT NULL,
`laufend` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german1_ci AUTO_INCREMENT=2 ;
Models:
- Code: Alles auswählen
<?phpclass FieldSize
extends AppModel
{ var $name = 'FieldSize'; var $validate = array( 'xachse' => array('numeric'), 'yachse' => array('numeric') );}?>
- Code: Alles auswählen
<?phpclass Game
extends AppModel
{ var $name = 'Game'; var $validate = array( 'name' => array('notempty'), 'aera_id' => array('numeric'), 'number_player_id' => array('numeric'), 'round_id' => array('numeric'), 'verbleibende_runden' => array('numeric'), 'waiting_time_id' => array('numeric'), 'xachse' => array('numeric'), 'yachse' => array('numeric'), 'laufend' => array('numeric') ); //The Associations below have been created with all possible keys, those that are not needed can be removed var $belongsTo = array( 'Aera' => array( 'className' => 'Aera', 'foreignKey' => 'aera_id', 'conditions' => '', 'fields' => '', 'order' => '' ), 'NumberPlayer' => array( 'className' => 'NumberPlayer', 'foreignKey' => 'number_player_id', 'conditions' => '', 'fields' => '', 'order' => '' ), 'Round' => array( 'className' => 'Round', 'foreignKey' => 'round_id', 'conditions' => '', 'fields' => '', 'order' => '' ), 'WaitingTime' => array( 'className' => 'WaitingTime', 'foreignKey' => 'waiting_time_id', 'conditions' => '', 'fields' => '', 'order' => '' ) //Hier noch irgendeine Bedingung für xache und yachse oder für die id von field_sizes );}?>
View:
- Code: Alles auswählen
<?php echo $form->create('Game');?> <fieldset
> <legend
><?php __
('Add Game');?></legend
> <?php echo $form->input('name'); echo $form->input('aera_id'); echo $form->input('number_player_id'); echo $form->input('round_id'); echo $form->input('verbleibende_runden'); echo $form->input('waiting_time_id'); echo $form->input('xachse'); //Diese beiden Inputs zu einem Dropdown machen echo $form->input('yachse'); echo $form->input('laufend', array( 'value' => '0' , 'type' => 'hidden')); ?> </fieldset
><?php echo $form->end('Submit');?>
Controller:
- Code: Alles auswählen
class GamesController
extends AppController
{ var $name = 'Games'; var $helpers = array('Html', 'Form'); function add
() { // Hier wieder beide Werte getrennt in die DB speichern if (!empty($this->data)) { $this->Game->create(); if ($this->Game->save($this->data)) { $this->Session->setFlash(__
('The Game has been saved', true)); $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__
('The Game could not be saved. Please, try again.', true)); } } $aeras = $this->Game->Aera->find('list'); $numberPlayers = $this->Game->NumberPlayer->find('list'); $rounds = $this->Game->Round->find('list'); $waitingTimes = $this->Game->WaitingTime->find('list'); $this->set(compact('aeras', 'numberPlayers', 'rounds', 'waitingTimes')); }}
Und hier noch wie ich das ohne CakePHP gemacht hatte:
- Code: Alles auswählen
- Code: Alles auswählen
echo '<select name="feldgroesse" style="width: 140px">';echo '<option value="0">Spielfeldgröße</option>';$feldgroesse = mysql_query("SELECT fgid, xachse, yachse FROM feldgroesse");while ($row_feldgroesse = mysql_fetch_assoc($feldgroesse)) { echo '<option value="'.$row_feldgroesse['fgid'].'" '; if (isset($_GET['feldgroesse']) &
;&
; $_GET['feldgroesse'] == $row_feldgroesse['fgid']) { echo 'selected'; } echo '>'.$row_feldgroesse['xachse'].'x'.$row_feldgroesse['yachse'].' Felder</option>';}echo '</select><br />';
Jetzt soll bei games/add sowas stehen wie:
Feldgröße
"Dropdown"20x10"Dropdown"
Ich weiß, es ist etwas kompliziert (und jetzt viel Code), aber ich hoffe Ihr könnt mir trotzdem helfen.