Zend Framework 2,使用选择

Posted

技术标签:

【中文标题】Zend Framework 2,使用选择【英文标题】:Zend Framework 2, using select 【发布时间】:2014-08-22 11:58:13 【问题描述】:

这是我需要从 zend ORM 生成的 SQL。它作为sql工作,但我需要从zend2 ORM重新创建它,当我获取'type'列的数据时,如果数据来自table1,它应该检索'type1',当它来自table2时,它应该是'type2'

select id,'type1' as type
from table1
UNION
select id,'type2' as type
from table2 where id = 1

我在 zend2 中使用过类似的东西,但没有给我正确的值。

    $select->from(array('a' => 'table1'));
    $select->columns(array(
        "id",
        "'type1'" => "type"
    ));

    $select2->from(array('t2' => 'table2'));
    $select2->columns(array(
        "id",
        "'type2'" => "type"
    ));
    $select->combine ( $select2 );

【问题讨论】:

【参考方案1】:

找到答案,

$select->from(array('a' => 'table1')); $select->列(数组( “ID”, 'type' => new Expression("'type1'") ));

$select2->from(array('t2' => 'table2'));
$select2->columns(array(
    "id",
    'type' => new Expression("'type2'")
));
$select->combine ( $select2 );

【讨论】:

以上是关于Zend Framework 2,使用选择的主要内容,如果未能解决你的问题,请参考以下文章