Saving Form Data in CakePHP

I had a problem persisting my data: "My form did not submit the correct array", I want to know what is the error in my code (after reading the cookbook). I understand that the array passed to the save method should be like this

array(
    (int) 0 => array(
        'value' => '',
        'id' => '',
        'indicator_id' => '283',
        'report_year_id' => '7',
        'Assurance' => array(
            (int) 0 => '1',
            (int) 1 => '2',
            (int) 2 => '3',
            (int) 3 => '4',
            (int) 4 => '5'
        )
    ),
    (int) 1 => array(
        'value' => '',
        'id' => '',
        'indicator_id' => '283',
        'report_year_id' => '6',
        'Assurance' => ''))

      

but when i debug my code i found that the data was passed to the save method:

array(
    'currentOrg' => array(
        'id' => '40'
    ),
    'IndicatorDatum' => array(
        '$cn' => array(
            'id' => '',
            'comment' => '',
            'reference' => ''
        ),
        (int) 0 => array(
            'value' => '',
            'Assurance' => ''
        ),
        (int) 1 => array(
            'value' => '',
            'Assurance' => ''
        ),
        (int) 2 => array(
            'value' => '',
            'Assurance' => ''
        ),
        (int) 3 => array(
            'value' => '',
            'Assurance' => ''
        ),

      

My form:

echo $this->DashboardForm->create('IndicatorDatum',array(
    'url' => array('controller'=>'indicator_data','action'=>'edit_group', 'dashboard'=>true, $thisGroup['IndicatorGroup']['id']),
    'novalidate'=>true
    ));
            <?  $cn = 0; 
            foreach ($years as $year) :
            echo $this->Form->hidden("IndicatorDatum.$cn.id");
            echo $this->Form->hidden("IndicatorDatum.$cn.state");
            echo $this->Form->input("IndicatorDatum.$cn.indicator_id",array(
                                                'type'=>'hidden', 'default'=>$iid
                                            )); 
        echo $this->Form->input("IndicatorDatum.$cnt.report_year_id",array(
                                            'type'=>'hidden', 'default'=>$yid
                                        )); 
            echo $this->Form->input('IndicatorDatum.$cn.value');                                   
            echo $this->Form->input("IndicatorDatum.$cn.Assurance", array('style'=>'width: 165px;',
                                                        'type'=>'select',
                                                        'multiple'=>true, 'options' => $assurances, 'selected' => $selected,'label' => false));
            $cn++;
            endforeach;

     echo $this->Form->submit(__('Save All'));

    ?>  

      

My controller:

if ($this->request->is('post')|| $this->request->is('put')) {
            $data = debug($this->request->data);
                        if ($this->IndicatorDatum->saveAll($this->request->data)) {
                $this->Session->setFlash(__('The indicator data has been saved'), 'flash/success');
                $this->redirect(array('action'=>'edit_group',$group_id));
            } else {
                $this->Session->setFlash(__('The indicator data could not be saved. Please verify the fields highlighted in red and try again.'), 'flash/error');
            }
        }

      

'UPDATE' error

I go DATABASE ERROR Error: SQLSTATE [42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual corresponding to your MySQL server version for the correct syntax to use next to it) GROUP BY s.state, s.indicator_datum_id) AS LatestStateUpdate

ON 'on line 4

SQL Query: SELECT IndicatorDatum

. id

, IndicatorDatumUpdate

. *, (CONCAT ( IndicatorDatum

. indicator_id

, '_', IndicatorDatum

. report_year_id

)) The AS IndicatorDatum__indexKey

the FROM astest

. indicator_data

AS IndicatorDatum

INNER JOIN (SELECT u.indicator_datum_id, MAX (u.created) as update_date, s.state FROM indicator_datum_states s INNER JOIN indicator_datum_updates u on u.id = s.indicator_datum_update_id WHERE s.indicator_date (s.indicator_date) .indicator_datum_id) AS LatestStateUpdate

ON ( IndicatorDatum

. id

= LatestStateUpdate

. indicator_datum_id

AND IndicatorDatum

. state

= LatestStateUpdate

. state

) INNER JOIN astest

. indicator_datum_updates

AS IndicatorDatumUpdate

ON ( IndicatorDatumUpdate

. indicator_datum_id

= LatestStateUpdate

. indicator_datum_id

And IndicatorDatumUpdate

. created

= LatestStateUpdate

. update_date

) WHERE IndicatorDatum

. id

= (NULL)

+3


source to share


1 answer


It throws an error because of your empty IN()

and doesn't seem to be related to saveAll()

:

WHERE s.indicator_datum_id IN ()

      



Where is this one SELECT

? I suggest checking if it's empty before building this condition.

(It's hard to tell where this is coming from - it looks like this is not the way out of any provided code.)

+1


source







All Articles