[英]codeigniter dropdown is not working
在下面的代碼點火器代碼中,我放置了控制器,模型和視圖。在我的登錄名中,我在下拉列表中創建了用戶名,密碼和大學來驗證用戶。但是在College_name下拉菜單中卻出現了錯誤消息:未定義變量:validate,消息:無效為foreach()提供的參數。請幫助我解決問題。 控制者
function college()
{
$this->load->helper('url');
$data = array();
$this->load->model("membership_model");
$data['validate'] = $this->Membership_model->validate();
$this->load->view('login_form');
}
function validate_credentials()
{
$this->load->model('membership_model');
$query = $this->membership_model->validate();
if($query) // if the user's credentials validated...
{
$data = array(
'username' => $this->input->post('username'),
'is_logged_in' => true
);
if($query->num_rows()>0){
$status = $query->row()->account_status;}
else {
$status = ''; }
//Account active
if($status == 'active')
{
$this->session->set_userdata($data);
redirect('site1/members_area');
}
else if ($status == 'inactive')//Account In active
{ $this->inactive();
}
else // incorrect username or password
{
$this->invalid();
}
}
}
模型:
function validate()
{
$this->db->where('username', $this->input->post('username'));
$this->db->where('password', md5($this->input->post('password')));
$this->db->where('college_name', $this->input->post('college_name'));
$query = $this->db->query("SELECT college_name FROM membership ");
$query = $this->db->get('membership');
return $query->result();
}
視圖:
<?php
echo form_open('login/validate_credentials');
echo form_input('username', 'Username');
echo form_password('password', 'Password');
$array = array();
foreach($validate as $row ){
$array[] = $row->college_name;
}
echo form_dropdown('validate', $array);
echo form_submit('submit', 'Login');
echo anchor('login/signup', 'Create Account');
echo form_close();
?>
嘗試在此處使用正確的駱駝保護套
$this->Membership_model->validate();
作為$this->membership_model->validate();
另外,您需要傳遞$ data變量以查看文件。
$this->load->view('login_form',$data);
編輯:
在validate()方法中,您對2個不同的查詢使用了相同的變量($ query),並返回了查詢結果。 確保在那里返回了正確的結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.