This is also posted on stackoverflow if you would like to see it with
syntax highlighting and such.
http://stackoverflow.com/questions/2063703/cakephp-saveall-fatal-error-call-to-a-member-function-getcolumntype
So I am creating a form builder. Users will login and then fillout the
forms that Admins have created. I am using saveAll() in my
"data_controller" "add" method.
This works fine and and looks like this:
//debug($this->data); prints the following
//app/controllers/data_controller.php (line 21)
Array
(
[Datum] => Array
(
[0] => Array
(
[bool_val] => 1
[field_id] => 56
[form_id] => 208
[user_id] => 1
)
[1] => Array
(
[bool_val] => 0
[field_id] => 64
[form_id] => 208
[user_id] => 1
)
)
)
// data_controller.php
// the add method is like this
function add() {
debug($this->data);
if (!empty($this->data) ) {
$this->Datum->create();
if ($this->Datum->saveAll($this->data['Datum'])) {
$this->Session->setFlash(__('The Datum has been saved',
true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Datum could not be saved.
Please, try again.', true));
}
}
$forms = $this->Datum->Form->find('list');
$fields = $this->Datum->Field->find('list');
$users = $this->Datum->User->find('list');
$statuses = $this->Datum->Status->find('list');
$this->set(compact('forms', 'fields', 'users', 'statuses'));
}
So that works fine and creates a series of new entries in the "data"
table of my MySQL database. My error comes when I try to use "saveAll
()" in my "edit" method. I have googled and googled and googled with
no luck. All of the articles say that my data structure should be
correct, or that is how I am understanding them.
So here is my view. It loops through to output checkboxes and other
form elements but we will just look at a simple check box only
example.
//field_view_datum.ctp
<?php
//debug($field_datum);
switch ($field['Type']['name']) {
case "check box" :
echo "<p>";
echo $form->label($field['FieldName'][0]['name']);
echo $form->hidden('Datum.'.$field_datum['id'].'.id', array
('value' => $field_datum['id']));
echo $form->hidden('Datum.'.$field_datum['id'].'.form_id',
array('value' => $formID));
echo $form->hidden('Datum.'.$field_datum['id'].'.field_id',
array('value' => $field['id']));
echo $form->hidden('Datum.'.$field_datum['id'].'.user_id',
array('value' => $userID));
$booly = ($field_datum['bool_val'] == 0) ? false : true;
$options = array('checked' => $booly);
echo $form->checkbox('Datum.'.$field_datum['id'].'.bool_val',
$options);
echo "</p>";
break;
My view will output the following HTML to the browser.
<p>
<label for="DatumFieldOne">Field One</label>
<input type="hidden" id="Datum164Id" value="164" name="data
[Datum][164][id]"/>
<input type="hidden" id="Datum164FormId" value="208" name="data
[Datum][164][form_id]"/>
<input type="hidden" id="Datum164FieldId" value="56" name="data
[Datum][164][field_id]"/>
<input type="hidden" id="Datum164UserId" value="1" name="data
[Datum][164][user_id]"/>
<input type="hidden" value="0" id="Datum164BoolVal_" name="data
[Datum][164][bool_val]"/>
<input type="checkbox" id="Datum164BoolVal" value="1"
checked="checked" name="data[Datum][164][bool_val]"/>
</p>
<p>
<label for="DatumFieldTwo">Field Two</label>
<input type="hidden" id="Datum165Id" value="165" name="data
[Datum][165][id]"/>
<input type="hidden" id="Datum165FormId" value="208" name="data
[Datum][165][form_id]"/>
<input type="hidden" id="Datum165FieldId" value="64" name="data
[Datum][165][field_id]"/>
<input type="hidden" id="Datum165UserId" value="1" name="data
[Datum][165][user_id]"/>
<input type="hidden" value="0" id="Datum165BoolVal_" name="data
[Datum][165][bool_val]"/>
<input type="checkbox" id="Datum165BoolVal" value="1" name="data
[Datum][165][bool_val]"/>
</p>
So then when I submit the form I get the following error:
Fatal error: Call to a member function getColumnType() on a non-
object in /cake/libs/model/model.php on line 949
The data I am passing and my controller method look like this:
//debug($this->data['Datum']); prints the following
app/controllers/data_controller.php (line 39)
Array
(
[164] => Array
(
[id] => 164
[form_id] => 208
[field_id] => 56
[user_id] => 1
[bool_val] => 1
)
[165] => Array
(
[id] => 165
[form_id] => 208
[field_id] => 64
[user_id] => 1
[bool_val] => 1
)
)
//data_controller.php
function edit($formid = null) {
debug($this->data['Datum']);
if (!empty($this->data) ) {
if ($this->Datum->saveAll($this->data['Datum'])) {
$this->Session->setFlash(__('The Datum has been saved',
true));
$this->redirect(array('controller' => 'forms',
'action'=>'index'));
} else {
$this->Session->setFlash(__('The Datum could not be saved.
Please, try again.', true));
$this->redirect(array('controller' => 'forms',
'action'=>'view', 'id' => '$formid'));
}
}
}
Any help that you can give would be much apriciated I have done tons
of searching and not found the correct answer. Sorry if this post is a
bit long winded.
Thanks,
Devin
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en