I'm using idiorm as an ORM library and the method as_array() doesn't work this is my code I get 2 errors

1- $market = $market->as_array();

PHP Fatal error: Call to a member function as_array() on a non-object

2- ->as_array();

PHP Fatal error: Call to a member function as_array() on a non-object

My code:

function ($market = 'affiliate', $category = array('all')) use ($app) {
    $market = \ORM::for_table('category')
        ->where('alias', $market)
        ->find_one();
    $market = $market->as_array();
    $category = @end($category);
    if ($category != 'all') {
        $category = \ORM::for_table('category')
            ->where('alias', $category)
            ->where_gt('category_id', 0)
            ->find_one()
            ->as_array();
        $items = \ORM::for_table('item')
            ->select('item.*')
            ->select('category.name', 'category_name')
            ->join('category', 'category.id = item.category_id')
            ->where('item.category_id', $category['id']);

没有正确的解决方案

其他提示

According to the Idiorm docs:

Any method chain that ends in find_one() will return either a single instance of the ORM class representing the database row you requested, or false if no matching record was found.

You should check to see if your query has returned any rows before calling as_array().

For example:

$market = \ORM::for_table('category')
    ->where('alias', $market)
    ->find_one();

if($market != false)
{
    $market = $market->as_array();
}

If this still gives an error then you may not have initialised Idiorm properly.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top