douyun8885 2015-06-16 05:31
浏览 29

codeigniter控制器和视图不工作

I have a question about CodeIgniter and how to get some information from some tables using a controller and then have it displayed in a view

I have it working using 6 tables, but I've changed the layout of the database and the names of the tables and I can't quite work out how to change the code to have it working again and I'm hoping it will be an easy 'find' for someone to look at and give me some pointers.

It has a couple of errors of

Message: Undefined variable: cluster_task

And then one for the date of

Message: Undefined index:item_date

Complaining about the view, but there’s probably the way I’ve defined in the controller, and I have tried changing it about 100 times and I cant see where the error(s) are?

This is what it comes out with in browser

From 3 June 2015 to 5 June 2015
Date        Support Item        Ref Number      Hours       Price       Cost    
4 June 2015                                         
3 June 2015                                         
5 June 2015                                         
5 June 2015                                         
1 January 1970  

The controller code is – there’s more but this should be the relevant part =

        $items = new Cluster_task();
        $items->where_in('id', $cluster_task_ids)->order_by('id', 'asc')->get();

         $cluster_task_id_count = array_count_values($cluster_task_ids);

        $dates = new List_item();
        $dates->where_in('user_list_id', $id)->where('item_date >=', $start)->where('item_date <=', $end)->order_by('cluster_task_id', 'asc')->get();
        if($items->exists()) {
           echo $data['item_count_item'] = $items->result_count();  
            $data['items'] = $items;   
            $data['dates'] = array();
            foreach($dates AS $date)
            {
              $data['dates'][$date->id] = array('item_date' => $date->item_date, 'cluster_tasks' => array());
            }  
            foreach($items AS $item)
            {
                for($count = 0; $count < $cluster_task_id_count[$item->id]; $count++)
                {
                        $data['dates'][$item->cluster_task_id]['cluster_tasks'][$item->cluster_task_id] = array(
                            'name' => $item->cluster_task_support_item
                        );
                }
            }
        }         
        $data['start'] = $start;
        $data['end'] = $end; 
        $this->cfd->build('diet/preview_claim', $data);

And the view code is – again, there’s more but this should be the relevant part =

<table class="atable">
<tr>
  <th colspan="12">From <?php echo date('j F Y', strtotime($start)) ?> to <?php echo date('j F Y', strtotime($end)) ?></th>
</tr>
<tr>
<td>Date</td>
<td>Support Item</td>
<td>Ref Number</td>
<td>Hours</td>
<td>Price</td>
<td>Cost</td>
</tr>

<?php
foreach($dates AS $date) {             
    $date = $date['item_date'];        //item_categories - name ie fruit
     echo '<td class="special_column1">'.date('j F Y',    strtotime($date)).'</td>';
foreach($date['cluster_tasks'] AS $cluster_task)    
{
        echo '<tr>';
        echo '<td class="special_column1">'.date('j F Y', strtotime($date)).'</td>';
        echo '<td class="special_column3">'.$cluster_task['name'].'</td>';
        echo '</tr>';
        $name = '';
   }
}
?>
</table>

thanks so much for your time.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用