简体   繁体   English

codeigniter 表单下拉添加编辑设置值

[英]codeigniter form drop down add edit with set value

I'm trying to use one form to perform add and edit functions.我正在尝试使用一种表单来执行添加和编辑功能。 I'm currently saving officer's id (retrieving officers name and id from officer table) and saving the id into an 'admin' table along with other information.我目前正在保存军官的 ID(从军官表中检索军官的姓名和 ID)并将 ID 与其他信息一起保存到“管理员”表中。

Adding a new record works fine but I am not able to retrieve the saved details to be able to edit the officer's details using drop down.添加新记录可以正常工作,但我无法检索保存的详细信息,以便能够使用下拉菜单编辑官员的详细信息。

In the controller I have the following code that stores officer's details from 'officer' table into an array在 controller 我有以下代码将官员的详细信息从“官员”表存储到数组中

<?php $data['OfficersToDisplay'] = $this->officers_model->Officers(TRUE);?>

In the view I have the code below that outputs officer's name:在视图中,我有以下输出官员姓名的代码:

<?php  $idOfficer = @field($this->validation->idOfficer, $item->idOfficer);  ?>
<tr>
<td><label>Officer</label></td>
<td>
<?php echo form_dropdown('idOfficer', $OfficersToDisplay, set_value('idOfficer'));?>
 <span> <?php echo form_error('idOfficer'); ?> </span>
</td>
</tr>

It will be great if someone can let me know what code needs to be added/updated so that current(saved) officer's details is added to the drop down box along with other ones.如果有人可以让我知道需要添加/更新哪些代码,以便将当前(保存的)官员的详细信息与其他信息一起添加到下拉框中,那就太好了。

You might want to check the userguide from CI: http://codeigniter.com/user_guide/helpers/form_helper.html您可能需要查看来自 CI 的用户指南: http://codeigniter.com/user_guide/helpers/form_helper.html

A good example is shown there how to use the form_dropdown function.一个很好的例子展示了如何使用 form_dropdown function。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM