Codeigniter:如何在View中调用模型函数?

时间:2014-04-16 10:56:23

标签: php codeigniter templates

我有模型并定义了2个功能 1.getMember() 2. getMemberCommunity($ member_id)

控制器代码

 public function index($pass=null){                  
      $this->load->model('member_model');
      $data['query']=$this->member_model->getMember();       
      $this->load->view('backend/project',$data);
}

查看

foreach($query as $row) {     
    // i want to call my another model function ? 
    //please give me any solutions ya tips   
}

1 个答案:

答案 0 :(得分:0)

您可以通过加入成员表,其中成员ID等于成员社区表中的成员ID,我可以这样做,我想这就是您想要的:

模型

public function getMembers(){                  

    $this->db->from('members')
             ->join('member_community', 'members.id = member_community.member_id', 'left');

    $members = $this->db->get();

    return $members;

}

控制器

public function index($pass=null){                  
    $this->load->model('member_model');
    $data['query']=$this->member_model->getMembers();       
    $this->load->view('backend/project',$data);
}

查看

foreach($query->result_array() as $row) {     
    // do whatever in here      
}