CodeIgniter 和 MVC/OOP 也是新手。我目前正在尝试解决的问题涉及 2 张桌子。
画廊表
ID
姓名
客户ID
客户表
ID
姓名
图库['clientID'] 引用了客户端['id'],因此我可以检索名称。目前我的 gallery_model.php 文件看起来像
class Gallery_model extends CI_Model
{
public function __construct()
{
$this->load->database();
}
//Get all in progress galleries from client
public function get_progress($id = FALSE , $clientRef = '205')
{
if($id == FALSE) {
$query = $this->db->get_where('gallery', array('clientRef' => $clientRef, 'finish' => '0' ));
return $query->result_array();
}
}
//Get all proofed galleries from client
public function get_proofed($id = FALSE , $clientRef = '205')
{
//get all galleries from client
if ($id == FALSE) {
$query = $this->db->get_where('gallery',array('clientRef' => $clientRef, 'finish' => '1'));
return $query->result_array();
}
}
//get the gallery selected
public function get_gallery($id , $clientRef = '205')
{
//This returns individual galleries
$query = $this->db->get_where('gallery', array('id' => $id));
return $query->row_array();
}
}
我的控制器看起来像:
public function index()
{
//Proofed Albums
$data['gallery'] = $this->gallery_model->get_proofed();
//Albums that are in progress
$data['in_progress'] = $this->gallery_model->get_progress();
$this->load->view('templates/header',$data);
$this->load->view('gallery/index',$data);
$this->load->view('templates/footer');
}
然后视图的输出是
$gallery['name'] - $gallery['clientId']
像这样的最佳实践是什么。我知道这可能很简单,但我想开始正确地做这件事。我应该使用$this->db->join();
在此先感谢您的帮助。