2015-03-18 15:14:41 4947次浏览 3条回答 0 悬赏 10 金钱
[
    'label'=>'确认订单',
    'format'=>'raw',
    'value'=>function($model,$model1){
        Modal::begin([
            'id'=>'myModal',
            'header' => '<h2>增加人数</h2>']);
            $form = ActiveForm::begin(['action' => ['order/update','id'=>$model->id,'cc'=>1], 'method'=>'post']);
            $form->errorSummary($model);
            echo $form->field($model1,'club_id')->textInput(['value'=>"order_booktee.club_id"]);
            echo $form->field($model, 'buyer_id')->textInput() ;
            echo $form->field($model, 'status')->textInput() ;
            echo Html::submitButton( Yii::t('app', '增加人数'), ['class' =>  'btn btn-success']);
            ActiveForm::end();
        Modal::end();
        return Html::button('<b>增加人数</b>',[ 'data-target'=>'#myModal','datatoggle'=>'modal']);
    }
],

我在gridview中用了个modal组件 想在modal里面显示club_id这个字段 但是这个字段是另外一张表的字段 就是关联的那张表 请问我应该怎么写才能把这个字段显示并把内容显示出来?求教啊

  • 回答于 2015-03-18 15:52 举报

    试试这个:

    public function getClubId()
    {
        return $this->hasOne(order_booktee::className(), ['club_id' => 'id']);
    }
    
    4 条回复
    回复于 2015-03-18 15:57 回复

    这个是关联查询吧-- 我关联查询好像已经设置好了

    回复于 2015-03-18 16:40 回复

    你现在处理的表示被关联表(从表)吧? 可能是你的问题我理解错了。不过下面的说明可以参考下:

    Apart from  hasMany() ,  ActiveRecord also has the  hasOne() method, which
    accepts the same arguments, but the meaning of the second argument is changed:
    in  hasMany() we point from the related table to this table, but in  hasOne() , we point
    from this table to the related one.
    Note that we don't technically need the  FOREIGN KEY defined in the database tables
    for this relation to work, as we specify the relation manually at the application level.
    The foreign keys definition is there for two reasons:
    •  It's a documentation in code: anyone reading the database schema will be
    able to understand that there is a logical relation between tables.
    •  Gii can automatically generate the relation methods based on the foreign
    keys defined in tables. It generates relation methods from both sides
    of the relation;
    
    回复于 2015-03-18 16:48 回复

    对 我想在当前页面操作从表的字段;大哥,我能弱弱的说一句不懂英语吗?

    回复于 2015-07-07 18:24 回复

    能请问下,你是怎么实现并解决这类问题的吗?

  • 回答于 2015-03-18 16:49 举报

    多表录入的话,可以传两个model给ActiveForm,具体做法可以参照《Web Application Development with Yii 2 and PHP》中的例子,群文件中有下载。

    1 条回复
    回复于 2015-03-18 17:03 回复

    谢谢哥 不过我试了 gridview里面传不进从表的model 要报错的

  • 回答于 2015-07-07 18:23 举报

    只能传入两个model么?这种方式看起来特别的不爽,而且也非常的麻烦。需要处理两个model之间的关系,还要在前台通过html代码进行合理的排位,正确的显示。然后在点击提交按钮之后,对后台再做数据的保存。也太麻烦了点吧?
    难道yii2 或者php中就没有能够关联两者关系,然后在前台很容易就操作的方法吗?

您需要登录后才可以回答。登录 | 立即注册
kkk
副董事长

kkk

注册时间:2015-03-06
最后登录:2023-06-19
在线时长:87小时58分
  • 粉丝5
  • 金钱31760
  • 威望0
  • 积分32630

热门问题