无法使用cakephp在数据库中插入开始日期和结束日期

时间:2014-10-11 15:47:02

标签: mysql date cakephp

我想使用cakephp在数据库中插入开始日期和结束日期的值。如果我取消注释$data = $controller->request>data;然后我得到这样的错误:警告(2):不能使用标量值作为数组[APP \ Model \ MattersCase.php,第40行]但是当我评论$data = $controller->request>data;时数据已插入,但开始日期和结束日期的值为0000-00-00

cases.ctp

    <tr>
<td valign=top class="form_label_width">Start Date:</td>
                        `enter code here`<td><?php echo $this->element("date", array('name' => 'data[MattersCase][start_date]', 'id' => 'start_date', 'value' => cleanDate($global_date_format, strtotime($start_date)), 'required' => false)); ?></td>
                    </tr>
                    <tr>
                        <td valign=top>End Date:</td>
                        <td><?php echo $this->element("date", array('name' => 'data[MattersCase][end_date]', 'id' => 'end_date', 'value' => cleanDate($global_date_format, strtotime($end_date)), 'required' => false)); ?>

                        </td>
                    </tr>

MattersCase.php

public function execute(&$controller, $task, $case_id)
    {          

       $data = $controller->request>data;
       $types = $controller->MattersCategory->getCategoryListNew12(0, true);
       $controller->set("types", $controller->sanitizeHTML($types));

       $providertypes = $controller->MattersUserAccount->getProviderTypes(0, true);
       $controller->set("providertypes", $controller->sanitizeHTML($providertypes));

        switch($task)
        {
            case "addnew":
            {       
                if (!empty($controller->request->data))
                {
                    $this->create();                                                
                    echo "clean out--".$data['MattersCase']['start_date'] = cleanDate("Y-m-d H:i:s", strtotime(str_replace("-", "/", $controller->request->data['MattersCase']['start_date'])));
                    //echo "clean--".$data['MattersCase']['start_date'] = cleanDate("Y-m-d H:i:s", strtotime(str_replace("-", "/", $controller->request->data['MattersCase']['start_date'])));

                    if($this->save($data))
                    //if ($controller->MattersCase->save($controller->request->data))
                    {
                        echo "<pre>";
                        print_r($controller->request->data);
                        $controller->Session->setFlash(__('Data added.', true));
                            //$controller->redirect(array('action' => $action));
                    }
                    else
                    {
                        $controller->Session->setFlash('Sorry, data can\'t be saved.', 'default', array('class' => 'error'));
                    }
                    if ($controller->MattersCase->save($controller->request->data))
                    {

                        $controller->Session->setFlash(__('Data added.', true));
                        //$controller->redirect(array('action' => 'cases'));
                    }
                    else
                    {
                        $controller->Session->setFlash('Sorry, data can\'t be saved.', 'default', array('class' => 'error'));
                    }
                }

            } break;

        }
    }
}

0 个答案:

没有答案