1

Other model data not showing in my Gridview.

I have 2 models,ListForms and Lists. I want to show list name from Lists on listforms gridview. This is my code.

ListForms Model:

class ListForms extends \yii\db\ActiveRecord{

       // relation name
        public $listname;            

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'listForms';
    }     

  public function getListname() {   
      return $this->hasOne(Lists::classname(), ['listid' => 'listids']);                       
}

ListForms GridView:

[
 'label'=>'List Name',
 'attribute' => 'listname',
 'value' => 'listname.listname'
],

ListFormsSearch:

   public function search($params){                  
    $query = ListForms::find();
            $query->joinWith(['listname']);         
            //...           
    }
4

1 回答 1

2

消除

public $listname;       

来自模型,因为您在模型中声明了变量,所以它不会从数据库中获取并显示。基本上它在很多地方都行不通。

于 2014-12-16T23:08:44.977 回答