获取codeigniter中的数据会导致下拉列表出现致命错误。
致命错误:在第32行的C:\ xampp \ htdocs \ project \ admin \ application \ models \ blogs_model.php中调用未定义的方法Blogs_model :: where()
博客:
function add()
{
$data['categorylist']=$this->blogs_model->categories_dropdown();
$data['mainpage']='blogs';
$data['mode']='add';
$this->load->view('templates/template',$data);
}
function addblogs()
{
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<br /><span class="error"> ','</span>');
$this->form_validation->set_rules('category_id','Category Name' , 'required');
$this->form_validation->set_rules('blog_title','Blog Title');
$this->form_validation->set_rules('description','Blog Description');
if($this->form_validation->run()== FALSE)
{
$data['categorylist']=$this->blogs_model->categories_dropdown();
$data['mainpage']='blogs';
$data['mode']='add';
$this->load->view('templates/template',$data);
}
else
{
$this -> blogs_model -> insertblogs();
$this->flash->success('<h2>blogs Added Successfully!</h2>');
redirect('blogs');
}
}
Blogs_model
function categories_dropdown()
{
$this->table = 'category';
$this->where('status',1);
$categorylist=$this->dropdown('category_id','category_name');
return $categorylist;
}
查看:
<div class="element">
<label for="categoryname"><font color="black">Category Name</font></label>
<?php
$categorylist['']='--Select Category Name--';
$category_id="id='category_id'";
if($this->input->post('category_id')) $selected=$this->input->post('category_id');else $selected='';
echo form_dropdown('category_id',$categorylist,$selected,$category_id);
?>
<?php echo form_error('category_id', '<div class="error">', '</div>'); ?><br/><br/>
</div>
答案 0 :(得分:0)
Please update your model as follows.
function categories_dropdown()
{
$this->db->select('category_id','category_name');
$this->db->from('category');
$this->db->where('status',1);
$result = $this->db->get();
return $result->result();
}