dongqian1925 2017-03-06 07:56
浏览 29

从杂货店的多个表中列出

I just started exploring grocery crud. I want list the values from multiple tables linked. As per their guide/tutorials I tried to figure out the solution, but couldn;t able to find solution. Expected query and solution is on this link http://sqlfiddle.com/#!9/0c5faf/3

$crud = $this->generate_crud('admin_users_groups');
$crud->where('group_id','3');
$crud->columns('user_id','DistID');
$crud->display_as('user_id','user');
$crud->set_relation('id', 'dist_info', 'ref_idkey');
//$crud->set_relation_n_n('groups', 'users_groups','groups','user_id','group_id','description');
//$crud->set_relation('user_id', 'admin_users', '{username} - {first_name}{last_name}');
//$crud->set_relation_n_n('DistID', 'admin_users','dist_info','id','id','ref_idkey');
//$crud->set_relation('user_id', 'admin_users', 'email');    
//$crud->set_relation_n_n('id', 'admin_users_groups', 'admin_users', 'id','dist_id', 'name');
//$crud->set_relation_n_n('groups1', 'admin_users_groups', 'admin_groups','user_id', 'group_id', 'name');`

Can any one help me to reach to desired solution?

  • 写回答

1条回答 默认 最新

  • drhzc64482 2017-03-06 08:44
    关注

    You're just missing some columns in your table. But the real trick is you basically want to display the id column twice, first to show the id and then in the set_relation call, but you can't do that as obviously the library won't know which one is supposed to go where. You have two choices, create a custom model to allow a join of the two tables or use a callback to manually go get the data you need. The second choice should be much easier:

    $crud = $this->generate_crud('admin_users_groups');
    $crud->where('group_id','3');
    $crud->columns('id, 'group_id, 'user_id','DistID')
    $crud->display_as('user_id','user');
    $crud->callback_column('DistID', array($this, 'callback_distID');
    ...
    }
    
    public function callback_distID($value, $row) {
        //Load your model for the 'dist_info'
        $this->load->model('Dist_info_model);
        $dist = $this->Dist_info_model->get_dist_info($row->id);
        return $dist['ref_idkey'];
    

    Then in your model:

    public function get_dist_info($id) {
        return $this->db->getwhere('Dist_info', array('recid'=>$id))->row_array; 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答