duanjuduo4573 2018-07-20 07:41
浏览 78
已采纳

Yii2 ArrayHelper :: map左连接选择

I have users, orders and plans. When client buy plan, data is save in orders , plans are in account_plan and the information for user is in table users. In table orders is when the plan start and when it is expired. I use for Select2 ArrayHelper, but do not show the column here is a query

 $masAcc[0] = Yii::t('app', 'Choose plan');
 $masAcc['----------------'] = 
ArrayHelper::map(
\backend\models\Orders::find()
->select('orders.*,account_planLang.name as name')
->leftJoin('orders_props','`orders_props`.`order_id`= `orders`.`id`')
->leftJoin('account_plan','`orders_props`.`product_id`=`account_plan`.`id`')
->leftJoin('account_planLang','account_plan.id=account_planLang.plan_id')
->where('`orders`.`dt_end`<CURDATE() + INTERVAL 5 DAY AND `orders`.`dt_end`<CURDATE()')
->all(), 'id', 'name');

but the error is : Getting unknown property: backend\models\Orders::name here is Select2:

 $form->field($model, 'account')->widget(Select2::classname(), [
                        'model' => $model,
                        'theme' => 'bootstrap',
                        'options' => [
                            'placeholder' => Yii::t('app', 'app.choose'),
                            'class' => 'form-control select2'
                        ],
                        'data' => $masAcc,
                        'pluginOptions' => [
                            'allowClear' => true,
                        ],
                    ]);
                    }
  • 写回答

2条回答 默认 最新

  • doujilou3903 2018-07-21 06:49
    关注

    I guess there is no need to use ArrayHepler::map(). Try this way:

    Orders::find()
      ->select('account_planLang.name as name, table_name.id as id')
      ->leftJoin('orders_props','`orders_props`.`order_id`= `orders`.`id`')
      ->leftJoin('account_plan','`orders_props`.`product_id`=`account_plan`.`id`')
      ->leftJoin('account_planLang','account_plan.id=account_planLang.plan_id')
      ->where('`orders`.`dt_end`<CURDATE() + INTERVAL 5 DAY AND `orders`.`dt_end`<CURDATE()')
      ->indexBy('id')
      ->column();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装