0

试图弄清楚我怎样才能正确地做到这一点。

print_r 看起来像这样:

Array ( [0] => stdClass Object ( [quote] => "Now that's wonderful!" ) ) 

表创建:

$tmpl = array ( 'table_open'  => '<table class="table" id="quotes-table">' );
$this->table->set_template($tmpl); 
print_r($quotes);
$data = array(
    array(form_checkbox('quotes'), 'Quote'),
    array(form_checkbox('quotes'), 'Testing Quote Here'),
    array(form_checkbox('quotes'), $quotes['quote'])
);
echo $this->table->generate($data); 
?>

更新:

问题虽然当我添加超过 1 行时,它只返回那一行。所以基本上我想要一个可以从查询返回的对象,以便在视图中我可以简单地执行 $quote->quote。这样,它将显示用户的所有报价。

<?php
$tmpl = array ( 'table_open'  => '<table class="table" id="quotes-table">' );
$this->table->set_template($tmpl);
$checkbox_data = array(
    'name'        => 'quote',
    'id'          => $quotes->id
); 
$data = array(
    array(form_checkbox($checkbox_data), 'Quote'),
    array(form_checkbox($checkbox_data), $quotes->quote)
);
echo $this->table->generate($data); 
4

2 回答 2

2

你没有说问题是什么,但如果你没有看到你的报价,试着改变这个:

array(form_checkbox('quotes'), $quotes['quote'])

进入这个:

array(form_checkbox('quotes'), $quotes[0]->quote)

编辑:一些额外的说明。

  Array ( [0] => stdClass Object ( [quote] => "Now that's wonderful!" ) ) 

你有一个 1 的数组,这是一个对象。对于数组,您使用 $array['key'] 对象 $object->key。如果你不能在控制器中改变它,你可以做这样的事情

$quotes = $quotes[0];
$quotes->quote;
于 2012-06-14T21:28:39.420 回答
1

在回答您的更新时,请尝试以下操作:

<?php

// Your query
$results = $this->db->get('quotes')->result();

$this->table->set_heading('Name', 'Quote');

foreach ($results as $result)
{
   // The name is the user's name, not sure if that's what you were going for.
   $this->table->add_row($result->name, $result->quote);
}

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

都在这里:http ://codeigniter.com/user_guide/libraries/table.html

于 2012-06-14T22:11:07.870 回答