Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Zend Framework 2:获取有序SQL调用_Php_Zend Framework2_Zend Db_Zend Db Table - Fatal编程技术网

Php Zend Framework 2:获取有序SQL调用

Php Zend Framework 2:获取有序SQL调用,php,zend-framework2,zend-db,zend-db-table,Php,Zend Framework2,Zend Db,Zend Db Table,我一直在尝试获取一个字段的订单ASC/DESC调用(假设为Crated),但我似乎不知道如何在ZF2中实现这一点 我错在哪里 namespace Todo\Model; class TodoTable extends AbstractTableGateway { public function __construct(Adapter $adapter) { $this->adapter = $adapter; $this->resultSetPrototype = n

我一直在尝试获取一个字段的订单ASC/DESC调用(假设为Crated),但我似乎不知道如何在ZF2中实现这一点

我错在哪里

namespace Todo\Model;
class TodoTable extends AbstractTableGateway {
public function __construct(Adapter $adapter) {
    $this->adapter = $adapter;
    $this->resultSetPrototype = new ResultSet();
    $this->resultSetPrototype->setArrayObjectPrototype(new Todo());

    $this->initialize();
}
public function fetchAll() {
    $resultSet = $this->select(array('user_id'=>$this->user_id));
return $resultSet;
}
}

可以使用闭包操纵选择对象,如下所示:

public function fetchAll() 
{
    // The Select object will be passed to your Closure
    // before the query is executed.

    $resultSet = $this->select(function (Select $select) use () {
        //$select->columns(array('user_id', 'email', 'name')); 
        $select->order('name ASC'); 
    });

    return $resultSet;
}
通过条件/位置的示例

public function fetchAll($someCondition) 
{
    // The Select object will be passed to your Closure
    // before the query is executed.

    $resultSet = $this->select(function (Select $select) use ($someCondition) {
        $select->columns(array('user_id', 'email', 'name')); 
        $select->order('name ASC'); 
        $select->where(array('user_id'=> $someCondition));
    });

    return $resultSet;
}

尝试
order()
方法->$user\u id=$this->user\u id$resultSet=$this->select(函数(select$select)使用($user_id){$select->order('created DESC');$select->where(数组('user_id'=>$user_id));});