I'm trying to create a page that you can create a new menu and edit a menu.
In that page I have a drop down list that lists all the menus that has been saved and a textbox where I can add or edit a menu.
The problem I'm having is that I can't get the drop down list to display the menus that are already in the database.
Here is my menus.php controller
Code:
function create()
{
$update_id = $this->uri->segment(3);
$submit = $this->input->post('submit', TRUE);
$query = $this->get('title');
foreach($query->result() as $row){
// $menu_id = $row->id;
// $menu_title = $row->title;
$data['title'] = $row->title;
}
if($submit == "Submit"){
//person has submitted the form
$data = $this->get_data_from_post();
}else{
if(is_numeric($update_id)){
$data = $this->get_data_from_db($update_id);
}
}
if(!isset($data)){
$data = $this->get_data_from_post();
}
$data['update_id'] = $update_id;
//$data['title'] = $this->get('title');
$data['view_file'] = "create";
$this->load->module('templates');
$this->templates->admin_template($data);
}
and this is my create.php view
Code:
<div class="row">
<div class="col-md-12">
<h2>Create Menus</h2>
<h5>Welcome Jhon Deo , Need to make dynamic. </h5>
</div>
</div>
<hr />
<?php
echo validation_errors("<p style='color: red;'>", "</p>");
echo form_open('menus/submit/'.$update_id);
?>
<div class="row">
<div class="col-md-12">
<form role="form">
<div class="form-group">
<select name="menu_id">
<?php
foreach($title as $titles){
echo '<option value="'.$titles.'">'.$titles.'</option>';
}
?>
</select>
</div>
<div class="form-group">
<label>Title</label>
<!-- <input class="form-control" /> -->
<?php
$data = array(
'name' => 'title',
'id' => 'title',
'value' => $title,
'class' => 'form-control',
);
echo form_input($data);
?>
</div>
<?php
$data = array(
'name' => 'submit',
'id' => 'submit',
'value' => 'Submit',
'class' => 'btn btn-success',
'style' => 'width: 100%',
);
echo form_submit($data);
?>
</form>
</div>
</div>
<?php
echo form_close();
?>