我在foreach
内有一个table
,用于加载包含行<tr>
的文件。
那个问题是所有的变量都是null并且我已经尝试用加载发送变量,你可以在下一个代码行中看到但是没有成功:
$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>
这是我在load-&gt;视图中包含的文件:
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 :(得分: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>