2015-07-13 25 views
3

我是CI新手,我按照網站的教程,然後我有這個錯誤。這是我的看法代碼:如何解決「類CI_Table的對象無法轉換爲字符串」?

$data = array('table_open' => '<table class = "table-bordered">'); 

echo $this->table->set_template($data); 

$col1 = array('data' => 'No'); 
$col2 = array('class' => 'col-md-4', 'data' => 'Agenda'); 
$col3 = array('class' => 'col-md-2', 'data' => 'Category'); 
$col4 = array('class' => 'col-md-2', 'data' => 'Date'); 
$option = array('class' => 'col-md-4', 'data' => 'Option'); 

echo $this->table->set_heading($col1, $col2, $col3, $col4, $option); 
// echo $this->table->set_heading('No', 'Agenda', 'Category', 'Date', 'Option'); 
$no = 1; 
if($agenda > 0) { 
    foreach($agenda as $ag) { 

     $item = $this->table->add_row($no++, $ag->agenda, $ag->agenda_cat, $ag->due_date, 
       anchor('agenda/edit' . $ag->id_agenda, 'Edit', array('class' => 'btn btn-info col-md-offset-1')) . " " . 
       anchor('agenda/delete' . $ag->id_agenda, 'Delete', array('class' => 'btn btn-danger')) 
      ); 
    } 
    echo $item; 
} 

echo $this->table->generate(); 

錯誤總是會發生的table->set_heading()table->add_rows()

而對於代碼回聲$this->table->set_template($data);它總是給出'1'作爲輸出。有人可以幫忙嗎?

+0

任何行指示? –

+0

沒有... –

+0

$ agenda數組在哪裏?那是什麼元素? – Nitin

回答

1

您的答案:

刪除所有echo除了echo $this->table->generate();這條線。

錯誤原因:

set_template函數返回true或false。如果你迴應這個,它會顯示1,因爲它返回true。

刪除echo從這一行echo $this->table->set_heading($col1, $col2, $col3, $col4, $option);它會顯示該錯誤消息。

set_heading函數返回object.You不能回顯對象。刪除echo或嘗試在該功能上使用print_rvar_dump

對於同樣的原因,你不能使用echo $item;

add_row函數返回的對象,而你是分配給$項目,你不能回聲對象。

+0

THANKYOU這麼多:) –

2

負載在控制器庫

$this->load->library('table'); 

Config/autoload.php

$autoload['libraries'] = array('table'); 

set_heading函數總是返回object.So沒有用的echo

因此您的代碼(刪除echo

<?php 
    $data = array(
     'table_open' => '<table class="table-bordered">'); 

    $this->table->set_template($data); 

    $col1 = array('data' => 'No'); 
    $col2 = array('class' => 'col-md-4', 'data' => 'Agenda'); 
    $col3 = array('class' => 'col-md-2', 'data' => 'Category'); 
    $col4 = array('class' => 'col-md-2', 'data' => 'Date'); 
    $option = array('class' => 'col-md-4', 'data' => 'Option'); 

    $this->table->set_heading($col1, $col2, $col3, $col4, $option); 
    // echo $this->table->set_heading('No', 'Agenda', 'Category', 'Date', 'Option'); 
    $no = 0; 

    if(empty($agenda)) 
    { 
     foreach($agenda as $ag) 
     { 
      $this->table->add_row($no++, $ag['agenda'], $ag['agenda_cat'], $ag['due_date'], 
       anchor('agenda/edit' . $ag['id_agenda'], 'Edit', array('class' => 'btn btn-info col-md-offset-1')) . " " . 
       anchor('agenda/delete' . $ag['id_agenda'], 'Delete', array('class' => 'btn btn-danger'))); 
     } 
    } 
    else 
    { 

    } 

codeigniter table

+0

THANKYOU所以它工作:) –

+0

高興地幫助@RizqiC –

+0

接受或upvote ?? –

相關問題