我想要一个简单的方法,它可以将 PHP Activerecord 结果作为简单/关联数组返回,而不是 ActiveRecord 对象数组。
在 Ruby 中,我相信这可能是通过.map()
方法完成的。(我不是红宝石人......)
我想要的是一个简单的方法调用,比如toArray()
在 Zend_DB_Table 中,而不是 foreach 或类似的东西,但我似乎无法在他们的docs中找到它。
在 PHP ActiveRecord 中获得结果非常简单:
$settings = SystemSettings::all();
但它会返回如下内容:
[0] => SystemSettings Object
(
[errors] =>
[attributes:ActiveRecord\Model:private] => Array
(
[param] => author
[value] => Hawle
)
[__dirty:ActiveRecord\Model:private] => Array
(
)
[__readonly:ActiveRecord\Model:private] =>
[__relationships:ActiveRecord\Model:private] => Array
(
)
[__new_record:ActiveRecord\Model:private] =>
)
[1] => SystemSettings Object
(
[errors] =>
[attributes:ActiveRecord\Model:private] => Array
(
[param] => base_url
[value] => example.com
)
[__dirty:ActiveRecord\Model:private] => Array
(
)
[__readonly:ActiveRecord\Model:private] =>
[__relationships:ActiveRecord\Model:private] => Array
(
)
[__new_record:ActiveRecord\Model:private] =>
)
虽然这在很多情况下真的很棒,但在这里,我只想有一个简单的数组,如下所示:
Array
(
[author] => Hawle
[base_url] => example.com
)