我想从两个不同的表中显示每个父类别的类别列表和子类别?

时间:2014-08-21 07:55:26

标签: php codeigniter-2 categories

我的桌子

tbl_company(id,user_id,name,description)
tbl_project(id,name,company_id)

在控制器中:

public function manage() {
  $this->load->model('company/companymodel');
  $companys = $this->companymodel->get();
  $companydata = array();
  foreach ($companys as $key => $company) {
    $companydata[$key] = $company;
    //$this->load->model('projectmodel');
    $Projects = $this->projectmodel->get($company->company_id);
    //debug($Projects);
    $companydata[$key]->projects = $Projects;
  }
  //debug($companydata);
  $data = array(
      'content' => 'project/manage',
      'companydata' => $companydata,
    );
  //debug($data);
  $this->load->view('dashboard_wrapper',$data);
}

在视图中:

<div class="box-content">
  <table class="table table-striped table-bordered bootstrap-datatable datatable">
  <?php foreach( $companydata as $company){ ?>
    <h3><?php echo $company->company_name;  ?></h3>
    <?php foreach($company->projects as $project) { ?>
      <li><?php echo $project->name;  ?></li>
    <?php } ?>
  <?php } ?>
  </table>            
</div>

我需要在相关公司的相关项目中显示:

  • 公司1
    • PROJECT1
    • 项目2
    • 项目3
  • Company2的
    • PROJECT1
    • 项目2
    • 项目3

0 个答案:

没有答案