2013-08-29 178 views
0

我有一個foreachtable加載文件的行<tr>
那問題是,所有的變量都無效,我已經嘗試過與負載發送變量,你可以在接下來的代碼行看到,但沒有成功:Codeigniter包含文件變量空

$this->load->view('pedidos/tarefas/tarefa_table', $task); 

這是我的表:

<table> 
    <thead> 
     <tr> 
      <th>ID</th> 
      <th>Utilizador</th> 
      <th>Entidade</th> 
      <th>Descrição</th> 
      <th>Data Limite</th> 
      <th>Estado</th> 
      <th>Ações</th> 
     </tr> 
    </thead> 
    <tbody> 
     <?php 
      foreach ($tasks as $task) { 

       $this->load->view('pedidos/tarefas/tarefa_table', $task); 

      } 
     ?> 
    </tbody> 
</table> 

這是我包括在負載>查看文件:
tarefa_table.php

<tr class="odd gradeX"> 
    <td><?php print_r($task->id); ?></td> 
    <td><?php echo substr($task->user->name, 0, 20); if(intval(strlen($task->user->name)>=20))echo ".."; ?></td> 
    <td><?php echo substr($task->entidade->name, 0, 20); if(intval(strlen($task->entidade->name)>=20))echo ".."; ?></td> 
    <td><?php echo substr($task->descricao, 0, 30); if(intval(strlen($task->descricao)>=30))echo ".."; ?></td> 
    <td style="<?php 
     if ($task->status_id <= 2 || $task->status_id >= 6) { 
      if (date('Y-m-d', strtotime($task->data_fim)) == date('Y-m-d')) { 
       echo "color: orange"; 
      } elseif (date('Y-m-d', strtotime($task->data_fim)) < date('Y-m-d')) { 
       echo "color: red"; 
      }else{ 
       echo "color:#274156"; 
      } 
     } ?>"><?php echo date('d-m-Y', strtotime($task->data_fim)) ?> 
    </td> 
    <td><?php 
     if($task->status_id <= 2 && date('Y-m-d', strtotime($task->data_fim)) < date('Y-m-d')){ 
      echo "Atraso"; 
     }else{ 
      switch ($task->status_id) { 
       case 1: echo "Ativo"; break; 
       case 2: echo "Atraso"; break; 
       case 3: echo "Pendente"; break; 
       case 4: echo "Concluído"; break; 
       case 5: echo "Cancelado"; break; 
       case 6: echo "Ativo"; break; 
       case 7: echo "Atraso"; break; 
       default: echo "Não Definido"; break; 
     }}?> 
    </td> 
    <td class="center">     
     <a href="<?php echo base_url() . 'pedidos/view_task/' . $task->id ?>" title="Ver" class="tip"> 
      <button class="btn btn-link btn-mini"><span class="icon16 icomoon-icon-eye"></button> 
     </a>    
     <a href="<?php echo base_url() . 'pedidos/edit_task/' . $task->id ?>" title="Editar" class="tip"> 
      <button class="btn btn-link btn-mini"><span class="icon16 icomoon-icon-pencil-5"></button> 
     </a> 

     <!--<a href="<?php //echo base_url() . 'pedidos/deletetask/' . $task->id ?>" class="confirm-delete tip" title="Apagar"> 
      <button class="btn btn-link btn-mini"><span class="icon16 typ-icon-trashcan red"></button> 
     </a>--> 

    </td> 
</tr> 
+0

是什麼的'$ task'數據類型中'的foreach($任務作爲$任務)'線? –

+0

它是一個數據通過拋出$ tasks – CIRCLE

回答

0

爲什麼不通過加載你的數據在控制器視圖,環和在變量追加像 $tablecontent和公正的回聲它在你的第一個視圖

//controller 

function your_fucntion(){ 
$tablecontent=""; 
foreach ($tasks as $task) { 
$tablecontent.=$this->load->view('pedidos/tarefas/tarefa_table', $task,true); 
} 
$data['tablecontent']=$tablecontent; 
$this->load->view('your view path', $data); 
} 

//view 
<table> 
    <thead> 
     <tr> 
      <th>ID</th> 
      <th>Utilizador</th> 
      <th>Entidade</th> 
      <th>Descrição</th> 
      <th>Data Limite</th> 
      <th>Estado</th> 
      <th>Ações</th> 
     </tr> 
    </thead> 
    <tbody> 
     <?php 
     echo $tablecontent; 
     ?> 
    </tbody> 
</table> 
+0

不幸的是這並沒有幫助我。是否有另一種方法將$任務傳遞到外部文件'tarefa_table.php'? – CIRCLE