Zend framework zendframework中的数据提交

Zend framework zendframework中的数据提交,zend-framework,Zend Framework,在我的zend项目中,我想显示一些健康问题以及一个下拉框和一个文本区域。我的控制器和视图如下所示 class IndexController extends Zend_Controller_Action { } -index.phtml- <table border='1'> <tr> <th>Name</th> <th>&nbsp;</th> <th>&n

在我的zend项目中,我想显示一些健康问题以及一个下拉框和一个文本区域。我的控制器和视图如下所示

class IndexController extends Zend_Controller_Action
{

}

-index.phtml-

<table border='1'>
<tr>
    <th>Name</th>       
    <th>&nbsp;</th>
    <th>&nbsp;</th>
</tr>
<?php foreach($this->healthproblems as $prob) : ?>
<tr>
    <td><?php echo $this->escape($prob->healthproblem_name);?></td>
    <td><select id="ddl_<?php echo $prob->prob_id; ?>">
            <option selected="selected">--Select--</option>
            <option>Yes</option>
            <option>No</option>
        </select></td>
    <td><input type="text" style="width: 50px" value=""></input></td>

</tr>

<?php endforeach; ?>
<tr><td colspan="3" align="center">
<input type="submit" id="submit" value="Submit" ></input></td></tr>

我的问题是“如何将这些数据添加到数据库中?”字段,如problemid和note。是否有其他替代方法?一个表中包含的所有问题,我想将每个人的问题插入另一个表中。请帮助我。

首先,我建议您使用Zend_表单,而不是从头开始创建表单

第二,, 要解决您的问题,您需要在表单中隐藏一个person\u id和problem\u id字段,其中包含person和problem id

在控制器中,您只需捕获数据,然后发送到下面描述的模型

然后,您需要使用insetPersonHealthProblem$data方法创建一个名为PersonProblem的新模型。它将从控制器接收数据

到目前为止,您的$data数组中会有类似的内容:

array(
'person_id' => 1,
'problem_id' => 15,
'hasproblem' => ', // 1 for yes and 0 for no
'note' => 'something'
);
因此,您的字段需要称为hasproblem,而不是在字段名中串联问题id,您将有一个隐藏字段

最后,在InsertPersonHealthProblem方法中,您将插入关系,并以如下方式结束:

id    |    person_id    |    problem_id   |   hasproblem   |   note   

1              1                 15                1          something
您的表单将如下所示:

<form method="POST" action="url('......')">
<input type="hidden" name="person_id" value="<?php echo $person_id; ?>" />
<input type="hidden" name="person_id" value="<?php echo $problem_id; ?>" />
<table border='1'>
<tr>
    <th>Name</th>       
    <th>&nbsp;</th>
    <th>&nbsp;</th>
</tr>
<?php foreach($this->healthproblems as $prob) : ?>
<tr>
    <td><?php echo $this->escape($prob->healthproblem_name);?></td>
    <td><select id="hasproblem">
            <option selected="selected">--Select--</option>
            <option>Yes</option>
            <option>No</option>
        </select></td>
    <td><input type="text" name="note" style="width: 50px" value=""></input></td>

</tr>

<?php endforeach; ?>
<tr><td colspan="3" align="center">
<input type="submit" id="submit" value="Submit" ></input></td></tr>
</form>
希望这对你有帮助

<form method="POST" action="url('......')">
<input type="hidden" name="person_id" value="<?php echo $person_id; ?>" />
<input type="hidden" name="person_id" value="<?php echo $problem_id; ?>" />
<table border='1'>
<tr>
    <th>Name</th>       
    <th>&nbsp;</th>
    <th>&nbsp;</th>
</tr>
<?php foreach($this->healthproblems as $prob) : ?>
<tr>
    <td><?php echo $this->escape($prob->healthproblem_name);?></td>
    <td><select id="hasproblem">
            <option selected="selected">--Select--</option>
            <option>Yes</option>
            <option>No</option>
        </select></td>
    <td><input type="text" name="note" style="width: 50px" value=""></input></td>

</tr>

<?php endforeach; ?>
<tr><td colspan="3" align="center">
<input type="submit" id="submit" value="Submit" ></input></td></tr>
</form>