[CakePHP] Year dropdown
Na de submit van het formulier krijg ik namelijk de volgende foutmelding: "Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Array' in 'field list'". De applicatie zoekt dus niet naar de value van de gekozen optie, maar neemt ineens de hele array van opties... Dat zal dan uiteraard ook de reden zijn waarom m'n validatieregel voor deze velden maar niet willen lukken.
Model (app/plugins/CoasterCms/Model/Attraction.php)
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
class Attraction extends CoasterCmsAppModel {
public $belongsTo = array(
'AttractionType' => array(
'className' => 'CoasterCms.AttractionType',
'foreignKey' => 'attraction_type_id'
),
'AttractionConstructor' => array(
'className' => 'CoasterCms.AttractionConstructor',
'foreignKey' => 'attraction_constructor_id'
),
'Area' => array(
'className' => 'CoasterCms.Area',
'foreignKey' => 'area_id'
)
);
public $validate = array(
'name' => array(
'rule' => 'notEmpty', // verplicht
'message' => 'Naam is verplicht.'
),
'attraction_type_id' => array(
'rule' => 'notEmpty', // verplicht
'message' => 'Type is verplicht.'
),
'subtype' => array(
'rule' => 'notEmpty', // verplicht
'message' => 'Subtype is verplicht.'
),
'area_id' => array(
'rule' => 'notEmpty', // verplicht
'message' => 'Themagebied is verplicht.'
),
'attraction_constructor_id' => array(
'rule' => 'notEmpty', // verplicht
'message' => 'Constructeur is verplicht.'
),
'opened' => array(
'rule' => 'notEmpty', // verplicht
'message' => 'Openingsjaar is verplicht.'
),
'intro' => array(
'rule' => 'notEmpty', // verplicht
'message' => 'Intro is verplicht.'
)
);
}
?>
class Attraction extends CoasterCmsAppModel {
public $belongsTo = array(
'AttractionType' => array(
'className' => 'CoasterCms.AttractionType',
'foreignKey' => 'attraction_type_id'
),
'AttractionConstructor' => array(
'className' => 'CoasterCms.AttractionConstructor',
'foreignKey' => 'attraction_constructor_id'
),
'Area' => array(
'className' => 'CoasterCms.Area',
'foreignKey' => 'area_id'
)
);
public $validate = array(
'name' => array(
'rule' => 'notEmpty', // verplicht
'message' => 'Naam is verplicht.'
),
'attraction_type_id' => array(
'rule' => 'notEmpty', // verplicht
'message' => 'Type is verplicht.'
),
'subtype' => array(
'rule' => 'notEmpty', // verplicht
'message' => 'Subtype is verplicht.'
),
'area_id' => array(
'rule' => 'notEmpty', // verplicht
'message' => 'Themagebied is verplicht.'
),
'attraction_constructor_id' => array(
'rule' => 'notEmpty', // verplicht
'message' => 'Constructeur is verplicht.'
),
'opened' => array(
'rule' => 'notEmpty', // verplicht
'message' => 'Openingsjaar is verplicht.'
),
'intro' => array(
'rule' => 'notEmpty', // verplicht
'message' => 'Intro is verplicht.'
)
);
}
?>
Controller (app/plugins/CoasterCms/Controller/AttractionsController.php)
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
class AttractionsController extends CoasterCmsAppController {
public $helpers = array('Html', 'Form', 'Session');
public $components = array('Session');
public function add() {
$this->set('attractionTypes', $this->Attraction->AttractionType->find('list'));
$this->set('areas', $this->Attraction->Area->find('list'));
$this->set('attractionConstructors', $this->Attraction->AttractionConstructor->find('list'));
if ($this->request->is('post')) {
$this->Attraction->create();
if ($this->Attraction->save($this->request->data)) { // data array opslaan
$this->Session->setFlash(__('De attractie werd succesvol toegevoegd.'));
return $this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('Er is een fout tijdens het toevoegen van de attractie opgetreden.'));
}
}
}
?>
class AttractionsController extends CoasterCmsAppController {
public $helpers = array('Html', 'Form', 'Session');
public $components = array('Session');
public function add() {
$this->set('attractionTypes', $this->Attraction->AttractionType->find('list'));
$this->set('areas', $this->Attraction->Area->find('list'));
$this->set('attractionConstructors', $this->Attraction->AttractionConstructor->find('list'));
if ($this->request->is('post')) {
$this->Attraction->create();
if ($this->Attraction->save($this->request->data)) { // data array opslaan
$this->Session->setFlash(__('De attractie werd succesvol toegevoegd.'));
return $this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('Er is een fout tijdens het toevoegen van de attractie opgetreden.'));
}
}
}
?>
View (app/plugins/CoasterCms/View/Attractions/add.ctp)
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
echo $this->Form->create('Attraction', array(
'type' => 'file',
'novalidate' => true, // browser validatie
'inputDefaults' => array(
'label' => true,
'div' => true
)
));
echo $this->Form->inputs(array(
'legend' => false,
'name' => array(
'label' => 'Naam'
),
'attraction_type_id' => array(
'label' => 'Type',
'empty' => 'Kies...'
),
'subtype' => array(
'label' => 'Subtype'
),
'area_id' => array(
'label' => 'Themagebied',
'empty' => 'Kies...'
),
'attraction_constructor_id' => array(
'label' => 'Constructeur',
'empty' => 'Kies...'
),
'opened' => array(
'type' => 'date',
'label' => 'Openingsjaar',
'dateFormat' => 'Y',
'minYear' => 1954,
'maxYear' => date('Y') + 1,
'empty' => 'Kies...'
),
'closed' => array(
'type' => 'date',
'label' => 'Sluitingsjaar',
'dateFormat' => 'Y',
'minYear' => 1954,
'maxYear' => date('Y'),
'empty' => 'Kies...'
),
'intro' => array(
'type' => 'textarea',
'label' => 'Intro',
'rows' => '10'
),
'content' => array(
'type' => 'textarea',
'label' => 'Inhoud',
'rows' => '10'
),
'show' => array(
'type' => 'radio',
'legend' => 'Tonen op website',
'options' => array(
'Y' => 'Ja',
'N' => 'Nee'
),
'value' => 'Y'
)
));
echo $this->Form->end('Opslaan');
?>
echo $this->Form->create('Attraction', array(
'type' => 'file',
'novalidate' => true, // browser validatie
'inputDefaults' => array(
'label' => true,
'div' => true
)
));
echo $this->Form->inputs(array(
'legend' => false,
'name' => array(
'label' => 'Naam'
),
'attraction_type_id' => array(
'label' => 'Type',
'empty' => 'Kies...'
),
'subtype' => array(
'label' => 'Subtype'
),
'area_id' => array(
'label' => 'Themagebied',
'empty' => 'Kies...'
),
'attraction_constructor_id' => array(
'label' => 'Constructeur',
'empty' => 'Kies...'
),
'opened' => array(
'type' => 'date',
'label' => 'Openingsjaar',
'dateFormat' => 'Y',
'minYear' => 1954,
'maxYear' => date('Y') + 1,
'empty' => 'Kies...'
),
'closed' => array(
'type' => 'date',
'label' => 'Sluitingsjaar',
'dateFormat' => 'Y',
'minYear' => 1954,
'maxYear' => date('Y'),
'empty' => 'Kies...'
),
'intro' => array(
'type' => 'textarea',
'label' => 'Intro',
'rows' => '10'
),
'content' => array(
'type' => 'textarea',
'label' => 'Inhoud',
'rows' => '10'
),
'show' => array(
'type' => 'radio',
'legend' => 'Tonen op website',
'options' => array(
'Y' => 'Ja',
'N' => 'Nee'
),
'value' => 'Y'
)
));
echo $this->Form->end('Opslaan');
?>
Iemand enig idee wat mij te doen staat om dit te fixen?
Gewijzigd op 17/01/2014 14:10:04 door Sam Clauw
Echt geen CakePHP'ers in de zaal? :)