我是CI的新学习者。 我想显示数据库中的数据。但它没有用。
控制器中的代码:
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->model("user_model");
$this->lang->load('basic', $this->config->item('language'));
// redirect if not loggedin
if(!$this->session->userdata('logged_in')){
redirect('login');
}
$logged_in=$this->session->userdata('logged_in');
if($logged_in['base_url'] != base_url()){
$this->session->unset_userdata('logged_in');
redirect('login');
}
}
public function index($limit='0')
{
$logged_in=$this->session->userdata('logged_in');
if($logged_in['su']!='1'){
exit($this->lang->line('permission_denied'));
}
$data['limit']=$limit;
$data['title']=$this->lang->line('userlist');
// fetching user list
$data['result']=$this->user_model->user_list($limit);
$this->load->view('header',$data);
$this->load->view('user_list',$data);
$this->load->view('footer',$data);
}
public function teachercontrol()
{
$logged_in=$this->session->userdata('logged_in');
$sut='2';
$this->db->where('su',$sut);
// fetching user list
$data['teacher']=$this->user_model->teachermodel();
$this->load->view('header',$data);
$this->load->view('user_list',$data);
$this->load->view('footer',$data);
}
我的模特:
function teachermodel(){
$this->db->order_by('savsoft_users.uid','desc');
$this -> db -> join('savsoft_group', 'savsoft_users.gid=savsoft_group.gid');
$query=$this->db->get('savsoft_users');
return $query->result_array();
}
我在视图中尝试打印,但它没有显示任何数据:
<?php print_r($teacher)?>
错误是什么? 而控制器中的索引功能(在教师控制器功能之上)效果很好 感谢
答案 0 :(得分:0)
将教师控制器中的条件放在模态中:
public function teachercontrol()
{
$logged_in=$this->session->userdata('logged_in');
$sut='2';
// fetching user list
$data['teacher']=$this->user_model->teachermodel($sut);
$this->load->view('header',$data);
$this->load->view('user_list',$data);
$this->load->view('footer',$data);
}
我的模特:
function teachermodel($sut = ""){
if($sut != "") {
$this->db->where('savsoft_users.su',$sut);
}
$this->db->join('savsoft_group', 'savsoft_users.gid=savsoft_group.gid', 'left');
$this->db->order_by('savsoft_users.uid','desc');
$query=$this->db->get('savsoft_users');
return $query->result_array();
}