Symfony: execute() return array?
<?p开发者_如何学编程hp
$result = $query->execute()
gettype($result); //output: object
?>
Why is this? While $result functions as an array (may be referenced so $result[i]), it is actually an object? I actually need to have an array to use array functions on it (e.g. array_slice()). Help?
Thanks.
execute();
return object Doctrine_Collection which implements SPL interfaces, such as ArrayAccess, Countable, Iterator so you can do basic array manipulations with it (such as $result[$i]
).
if you really need array, then you need to use $query->fetchArray();
instead
symfony itself doesn't do ORM, but i assume you are using doctrine (which is the default for symfony) - the execute() method returns a Doctrine_Collection. Maybe you want to take a look at the API documentation: http://www.doctrine-project.org/api/orm/1.2/doctrine/doctrine_query_abstract.html#execute()
usually there is no need to use any array methods on it.. if you only need a subset of the results, don't query for all your data. what exactly do you need?
精彩评论