将表单值从一个元素传递到cakephp中的表

时间:2013-02-20 14:44:55

标签: cakephp

我有一个IT查询系统,用户可以在其中添加查询。当我查看查询时,我应该能够添加对查询的响应。响应应该添加到名为it_query_responses的表中,模型名称是ItQueryResponse。

通过一个元素,我在view.ctp中包含了对IT查询的添加响应。我现在面临的挑战是元素没有将响应保存到it_query_responses表中。

这是我的响应控制器的添加功能

public function add() {
    if ($this->request->is('post')) {
        $this->ItQueryResponse->create();
        if ($this->ItQueryResponse->save($this->request->data)) {
            $this->Session->setFlash(__('The it query response has been saved'));
            $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The it query response could not be saved. Please, try again.'));
        }
    }
    $itQueries = $this->ItQueryResponse->ItQuery->find('list');
    $hrEmployees = $this->ItQueryResponse->HrEmployee->find('list');
    $itQueryStatuses = $this->ItQueryResponse->ItQueryStatus->find('list');
    $this->set(compact('itQueries', 'hrEmployees', 'itQueryStatuses'));
}

以下是我在view.ctp

中关闭div后调用元素的方法
<?php echo $this->element('ItQueryResponses/add'); ?>

这是我元素的代码

<?php echo $this->Form->create('ItQueryResponse'); ?>
<fieldset>
<legend><?php echo __('Add It Query Response'); ?></legend>
<?php
echo $this->Form->input('it_query_id');
echo $this->Form->input('hr_employee_id');
echo $this->Form->input('response');
echo $this->Form->input('it_query_status_id');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>   

提前谢谢。

0 个答案:

没有答案