Saturday, August 6, 2011

Strange problem with form err- array_key_exists() expects parameter 2 to be array

Hello bakers!

My name is Alberto, I'm using cakephp since 8 months ago, and this is
the first time that I face to this problem when I'm using a form.
While I was written this, I solved it, but I prefer to share with the
community what was the problem, just in case someone have it.

The model:
class Summary extends AppModel{
var $name = 'Summary';
var $useTable = 'summaries';
var $belongsTo = array(
'Summary' => array(
'className' => 'Event',
'foreignKey' => 'event_id'
)
);
var $validate;
}

The controller's method used:
function add($event_id = null) {

if (!empty($this->data)) {
$this->Summary->create();
$this->data['summary']['event_id']=$event_id;
if ($this->Summary->save($this->data)) {
$this->Session->setFlash(__('The summary has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The summary could not be saved.
Please, try again.', true));
}
}

The view for the Add function:
<?= $this->Form->create(null, array('url'=>'/summaries/add/'.
$event_id));?>
<?= $this->Form->input('title',array('label'=>__('Title',true)));?>
<?= $this->Form->input('summary',array('label'=>__('Summary',true)));?
>
<?= $this->Form->input('image',array('label'=>__('Image',true)));?>
<?= $this->Form->input('public',array('label'=>__('Make it
public',true)));?>
<?= $this->Form->end('Create Summary',array('label'=>'Create
Summary'));?>

In the view appears a message saying the following:
array_key_exists - [internal], line ??
Helper::setEntity() - CORE\cake\libs\view\helper.php, line 448
Helper::_initInputField() - CORE\cake\libs\view\helper.php, line 753
FormHelper::_initInputField() - CORE\cake\libs\view\helpers\form.php,
line 2203
FormHelper::hidden() - CORE\cake\libs\view\helpers\form.php, line 1214
FormHelper::create() - CORE\cake\libs\view\helpers\form.php, line 286
include - APP\views\summaries\add.ctp, line 1
View::_render() - CORE\cake\libs\view\view.php, line 731
View::render() - CORE\cake\libs\view\view.php, line 426
Controller::render() - CORE\cake\libs\controller\controller.php, line
909
Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 207
Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 171
[main] - APP\webroot\index.php, line 83

None of these urls are yours, everything is inside the framework. The
problem is that you dont have to procrastinate never ever when your
are coding. How to solve it? Go to your model and fill up the
$validate variable or remove it.

I hope that Google can index this just in case someone get the same
error.

Bye cookers!

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate