开发者

Dropdown Population

I am trying to populate my dynamic dropdown menu using CI:

My issue is that when I set my dropdown value and text ($formImageCaptionDropDown = array($get_images['id'] => $get_images['description']);) it does not display - just displays a blank dropdown box.

I have done print_r on my $get_images so I know that this is working correct.

I also know that I am to use $var['value'] because I have copied the format of another page that uses the images model and is working fine.

I just cannot seem to populate the dropdown menu

I have the following code:

<?php
//Setting form attributes
$get_images = $this->image_model->getImages();
$formImageCaption = array('id' => 'imageCaption', 'name' => 'imageCaption');
$formImageCaptionDropDown = array($get_images['id'] => $get_images['description']);
$formImageCaptionSelection = array开发者_JAVA百科('id' => 'captionSelection', 'name' => 'captionSelection');
$formSubmit = array('id' => 'submit','name' => 'submit','value' => 'Edit Caption');
?>
<div id ="formLayout">
<?php echo form_open('admin/imagecaption',$formImageCaption);
  echo form_fieldset(); 
?>
<p>Please Select A Caption Below To Edit: </p>

<?php echo form_label ('Caption:', 'caption');?>
<?php echo form_dropdown('caption', $formImageCaptionDropDown); ?>

<div id="errorCaption"><?php echo form_error('caption');?></div>
<span class="small">Required Field</span>

    <?php echo form_fieldset_close();
  echo form_close(); ?>
   </div>


I have resolved my issue by doing the following:

  1. I moved the line $get_images = $this->image_model->getImages(); into my controller as $data['$get_images'] = $this->image_model->getImages();

  2. In my view I did the following:

<?php foreach ($get_images as $image){
    echo '<option value="'.$image['id'].'">'.$image['description'].'</option>';
};
?>`
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜