【问题标题】:How can I select colums from multiple tables and display it in yii framework如何从多个表中选择列并在 yii 框架中显示
【发布时间】:2013-07-10 14:11:54
【问题描述】:

我正在开发用于 PHP Web 开发的 Yii 框架。现在我必须从四个以上的表中选择数据并使用连接将其显示为单个表。 假设我为表 test1、test2、test3、test4 创建了模型类,每个表包含两列。我需要显示一个包含所有四个表的列的表。 我如何在 yii 框架中做到这一点

【问题讨论】:

  • 所有表都相互关联吗??
  • @ninad 是的,它们都是相关的
  • @Ninad 查询类似于 - "Select a.id,b.id,c.id,d.id from test1 a,test2 b,test3 c,test4 d where a.id= b.id 和 c.id=d.id"
  • @Ninad 我在哪里可以修改我的查询
  • 当您为这些默认关系创建模型时,请参考这些关系以显示结果

标签: php yii


【解决方案1】:

以下是如何在单个模型中使用搜索连接模型的示例。它可以工作,但更好地理解关系表。

 public function searchItems($id)
    {
    $criteria=new CDbCriteria;
    $criteria->join .=' LEFT JOIN tbl_items as items ON od.ItemId = items.Id';
    $criteria->join .=' LEFT JOIN tbl_taxes as taxes ON t.ShippingState = taxes.State';
    $criteria->together = true;


    return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,

    ));
}

然后您可以使用以下方法将其称为数据提供者:

$model->searchItems(whatever you want to pass it);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-24
    • 2020-05-14
    • 2020-04-25
    • 2013-02-24
    • 2012-05-02
    • 2013-01-25
    • 1970-01-01
    相关资源
    最近更新 更多