ZF2又称具有谓词的Apigility SQL

时间:2014-09-25 01:05:13

标签: sql zend-framework2 apigility

我正在尝试在ZF2中使用谓词,以便查询名为date的{​​{1}}类型列

似乎任何列都没有用,我很新,我不确定从哪里开始......

column_date

这会返回错误 $query = $this->tableGateway->getSql()->select(); $predicate = new Where(); $query->where($predicate->equalTo('user_id' , $params['user_id'])); $query->where($predicate->equalTo('super_type', 'steep')); $query->where($predicate->greaterThan('column_date',$dateRangeArray[0])); $query->where($predicate->lessThan('column_date', $dateRangeArray[1])); $rowset = $this->tableGateway->select($query); $resultArr = $rowset->toArray(); ,错误user_id的内容。为什么?

column_date看起来像这样:

dateRangeArray

1 个答案:

答案 0 :(得分:0)

现在可以在Apigility的TableGateway中正常使用

    //parses into an array of YYYY-MM-DD
    $dateRangeArray = $transformer->parseDateRange($activity_date_range, "ymd");

    $start_date_formatted = date('Y-m-d', strtotime($dateRangeArray[0]));
    $end_date_formatted = date('Y-m-d', strtotime($dateRangeArray[1]));


    // Query 
    $query = $this->getSql()->select()
        ->where->equalTo('user_id' , $user_id)
        ->where->greaterThanOrEqualTo('field_date ', $start_date_formatted)
        ->where->lessThanOrEqualTo('fieldy_date',$end_date_formatted);


    $rowset = $this->select($query);
    $resultArr = $rowset->toArray();

    return $resultArr;