2011-04-10 3 views
0

나는 테이블을 생성하려면 다음 코드를HTML 테이블 내부 링크를 생성

$query = $this->search_employee->getAll($config['per_page'], $this->uri->segment(3)); 

    $this->table->set_heading('Name', 'Department'); 
    $tmp = array ('table_open' => '<table border="0" cellpadding="2" cellspacing="1" width="70%">'); 
    $this->table->set_template($tmp); 

    $data['main_content'] = 'display_professors'; 
    $data['table'] = $this->table->generate($query); 

내 질문에 내가 ID를/

을 view_employee에 대한 링크 이름 열에서 각 행에 아래 링크를 만들 수있는 방법이다

codeigniter의 table class을 사용하고 있습니다.

답변

2

이 작업을 수행 할 수있는 더 좋은 방법이있을 수 있습니다,하지만 난 단순히 쿼리 행을 통해 루프 테이블 행 만들 ...

if ($query->num_rows() > 0) 
{ 
    foreach ($query->result() as $row) 
    { 
     $this->table->add_row(anchor('view_employee/ID/' . $row->employee_id, $row->employee_name), $row->employee_department); 
    } 
} 

$data['table'] = $this->table->generate(); 

UPDATE :

당 이 답변에 대한 귀하의 의견,이 방법은 더 이상 자신의 예제보다 모델에 html로 퍼팅 볼 수 없습니다. 결국보기에서 수행 할 모든 방법은 <?= $table; ?> 또는 이와 유사합니다. 보기에 다음

$data['rows'] = array();  

if ($query->num_rows() > 0) 
{ 
    foreach ($query->result() as $row) 
    { 
     $this_row = array(); 
     $this_row['link'] = site_url('view_employee/ID/' . $row->employee_id); 
     $this_row['employee_name'] = $row->employee_name; 
     $this_row['employee_department'] = $row->employee_department; 

     $data['rows'][] = $this_row; 
    } 
} 

과 : 당신이 절대적으로 두 가지를 구분합니다

, 당신은 할 수

<table border="0" cellpadding="2" cellspacing="1" width="70%"> 
    <tr> 
    <th>Name</th> 
    <th>Department</th> 
    </tr> 
<? foreach($rows as $row): ?> 
    <tr> 
    <td><a href="<?= $row['link']; ?>"><?= $row['employee_name']; ?></a></td> 
    <td><?= $row['employee_department']; ?></td> 
    </tr> 
<? endforeach; ?> 
</table> 
+0

이 방법의 문제는 당신이에 "HTML"을 가하고 있다는 것입니다 모델... – ebecker

관련 문제