Voor een attractiefiche had ik graag de velden "openingsjaar" en "sluitingsjaar" gebruikt. Beide velden, respectievelijk "opened" en "closed" genaamd, heb ik in de tabel "attractions" het type "year" toegekend. Ik ben nu bezig met de actie "add" van de controller "AttractionsController.php" uit te werken maar ik bots op een probleem bij de eerder genoemde velden.

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)

<?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.'
)
);
}

?>

Controller (app/plugins/CoasterCms/Controller/AttractionsController.php)

<?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.'));
}
}
}

?>

View (app/plugins/CoasterCms/View/Attractions/add.ctp)

<?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');

?>

Iemand enig idee wat mij te doen staat om dit te fixen?
Echt geen CakePHP'ers in de zaal? :)

Reageren