[英]codeigniter dropdown is not working
In the below codeigniter code i have placed controller ,model and view .In my login i have create username ,password and college in dropdown for validate the user.But i got error in college_name drop down Message: Undefined variable: validate,Message: Invalid argument supplied for foreach().Pls help me to solve the issue. 在下面的代码点火器代码中,我放置了控制器,模型和视图。在我的登录名中,我在下拉列表中创建了用户名,密码和大学来验证用户。但是在College_name下拉菜单中却出现了错误消息:未定义变量:validate,消息:无效为foreach()提供的参数。请帮助我解决问题。 Controller 控制者
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();
}
}
}
model: 模型:
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();
}
view: 视图:
<?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();
?>
Try to use correct camel case here 尝试在此处使用正确的骆驼保护套
$this->Membership_model->validate();
as $this->membership_model->validate();
作为$this->membership_model->validate();
Also you need to pass the $data variable to view file. 另外,您需要传递$ data变量以查看文件。
$this->load->view('login_form',$data);
EDIT: 编辑:
In the validate() method you used the same variable ($query) for 2 different queries and return the query result. 在validate()方法中,您对2个不同的查询使用了相同的变量($ query),并返回了查询结果。 Make sure you had returned the correct result there. 确保在那里返回了正确的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.