在Kohana中,如何在读取ORM数据时动态指定列名



有可能这样做吗?显然,我提供的echo语句失败了,是否有一种方法可以使它们与ORM一起工作?

$record_columns = $records->list_columns();
$records = $records->find_all();
foreach ($record_columns as $column) {
    echo $record->$column;
    echo $record[$column];
}

谢谢,

Serhiy

像这样?对于Kohana 3.0。我在用这个。我没有尝试过Kohana 3.1,但它应该是类似的:

$result = ORM::factory('my_table')
   ->find_all();
$columns = Database::instance()
   ->list_columns('my_table');
foreach ($result as $row)
{
  foreach ($columns as $key => $value)
  {
    echo $row->{$key};
  }
}

最新更新