[eluser]cerberus478[/eluser]
I'm trying to create a drop down list that has all the menu titles and it has to be from the database.
It must show up on the pages create view.
It must also save the menu id to the pages table so that the two are linked.
I'm trying to do it in a hmvc structure.
When I try to view the pages create page I get these errors
I know with this error the dropdown is undefined, but wouldn't it be defined since I'm calling the menus module?
Quote:Severity: Notice
Message: Undefined variable: dropdown
Filename: views/create.php
Line Number: 24
and
Quote:Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: helpers/form_helper.php
Line Number: 331
menus controller
Code:
function dropdown(){
$data['dropdown'] = $this->menus_model->get_dropdown_tags();
return $data;
}
menus_model
Code:
function get_dropdown_tags()
{
$drop = $this->db->query('select title from menus');
$dropdowns = $drop->result();
foreach ($dropdowns as $dropdown)
{
$dropdownlist[$dropdown->title] = $dropdown->title;
}
$finaldropdown = $dropdownlist;
return $finaldropdown;
}
This is the pages controller
Code:
function create(){
$update_id = $this->uri->segment(3);
$submit = $this->input->post('submit', TRUE);
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();
}
//Calls the get_menus function for the drop down list
$this->get_menus();
$data['update_id'] = $update_id;
$data['view_file'] = "create";
$this->load->module('template');
$this->template->admin($data);
}
function get_menus(){
$this->load->module('menus');
$this->menus->dropdown();
}
my pages create view
Code:
[removed][removed]
[removed]bkLib.onDomLoaded(nicEditors.allTextAreas);[removed]
<h2>Create a page</h2>
<?php
echo validation_errors("<p red;'>", "</p>");
echo form_open('pages/submit/'.$update_id);
?>
<table width="900" cellpadding="8" cellspacing="0" border="1">
<tr>
<td> Title:
<?php
echo form_dropdown('dropdown', $dropdown);
?>
</td>
</tr>
<tr>
<td> Title:
<?php
$data = array(
'name' => 'title',
'id' => 'title',
'value' => $title,
'maxlength' => '230',
'size' => '50',
'style' => 'width: 320px;',
);
echo form_input($data);
?>
</td>
<td> Meta Title:
<?php
$data = array(
'name' => 'meta_title',
'id' => 'meta_title',
'value' => $meta_title,
'maxlength' => '230',
'size' => '50',
'style' => 'width: 320px;',
);
echo form_input($data);
?>
</td>
</tr>
<tr>
<td colspan="2"> Keywords:
<?php
$data = array(
'name' => 'keywords',
'id' => 'keywords',
'value' => $keywords,
'maxlength' => '230',
'size' => '50',
'style' => 'width: 800px;',
);
echo form_input($data);
?>
</td>
</tr>
<tr>
<td colspan="2"> Meta Description:
<?php
$data = array(
'name' => 'meta_description',
'id' => 'meta_description',
'value' => $meta_description,
'maxlength' => '230',
'size' => '50',
'style' => 'width: 700px;',
);
echo form_input($data);
?>
</td>
</tr>
<tr>
<td colspan="2" id="content"> Content:
<?php
$data = array(
'name' => 'content',
'id' => 'content',
'value' => $content,
'rows' => '30',
'cols' => '50',
'style' => 'width: 750px;',
);
echo form_textarea($data);
?>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<?php
echo form_submit('submit', 'Submit');
?>
</td>
</tr>
</table>
<?php
echo form_close();