2 models, one GridView

Hi guys, I want to get content of two tabels,which have no relation in one GridView. Any ideas,how to implement this ( Links are also welcome)

If i will copy following GridView, I have design,as it should be, but second View should represent second table. Furthermore, I will get error like this:




Unknown Property – [url="http://www.yiiframework.com/doc-2.0/yii-base-unknownpropertyexception.html"]yii\base\UnknownPropertyException[/url]

                

Setting unknown property: kartik\grid\GridView::dataProvider_telefon







Pjax::begin();

?>

<?=

GridView::widget([

    'dataProvider' => $dataProvider,

    'filterModel' => $searchModel,

    'columns' => $gridColumn,

    'headerRowOptions' => ['class' => 'kartik-sheet-style'],

    'filterRowOptions' => ['class' => 'kartik-sheet-style'],

    'export' => [

        'fontAwesome' => true

    ],

    'bordered' => true,

    'striped' => true,

    'condensed' => true,

    'responsive' => true,

    'hover' => true,

    'showPageSummary' => false,

    'panel' => [

        'type' => GridView::TYPE_SUCCESS,

        "heading" => "<h3 class='panel-title'><i class='glyphicon glyphicon-globe'></i> " . $this->title . "</h3>",

    ],

    'persistResize' => false,

    'toggleDataOptions' => ['minCount' => 10],

    'exportConfig' => true,

]);

?>

<?=

GridView::widget([

    'dataProvider_telefon' => $dataProvider_telefon,

    'filterModel' => $searchModel_telefon,

    'columns' => $gridColumn,

    'headerRowOptions' => ['class' => 'kartik-sheet-style'],

    'filterRowOptions' => ['class' => 'kartik-sheet-style'],

    'export' => [

        'fontAwesome' => true

    ],

    'bordered' => true,

    'striped' => true,

    'condensed' => true,

    'responsive' => true,

    'hover' => true,

    'showPageSummary' => false,

    'panel' => [

        'type' => GridView::TYPE_SUCCESS,

        "heading" => "<h3 class='panel-title'><i class='glyphicon glyphicon-globe'></i> " . $this->title . "</h3>",

    ],

    'persistResize' => false,

    'toggleDataOptions' => ['minCount' => 10],

    'exportConfig' => true,

]);

Pjax::end();

?>



Here is index of Controller:





    public function actionIndex() {

        $searchModel = new KontaktAdresseSearch();

        $searchModel_telefon = new KontaktTelefonSearch();

        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        $dataProvider_telefon = $searchModel_telefon->search(Yii::$app->request->queryParams);


        return $this->render('index', [

                    'searchModel_telefon' => $searchModel_telefon,

                    'dataProvider_telefon' => $dataProvider_telefon,

                    'dataProvider' => $dataProvider,

                    'searchModel' => $searchModel

        ]);

    }



second


GridView::widget([

    'dataProvider' => $dataProvider_telefon,

Ur sollution will throw out following error:





Getting unknown property: frontend\modules\kontakt\models\KontaktTelefon::postleitzahl




This error is 'caused by invalid $dataProvider in second GridView. I probably can’t call $dataProvider twice…

GridView tries to load an attribute for model2,which is in model1

[/code]

GridView tries to load an attribute for model2,which is in model1

[/quote]

because you are passing the same columns for both GridViews, to the second one you should pass columns from your second model not first.

‘columns’ => $gridColumn, //for the first widget

‘columns’ => $gridColumn2, // or something for the second widget

U are right. I noticed this [color="#0C0C0C"][font="Arial, sans-serif"][size="3"]carelessness, too! This is full code,which works…[/size][/font][/color]

[font="Arial, sans-serif"][color="#0c0c0c"]


[/color][/font]

[font="Arial, sans-serif"][color="#0c0c0c"]

Pjax::begin();

?>

<?=

GridView::widget([

    'dataProvider' => $dataProvider,

    'filterModel' => $searchModel,

    'columns' => $gridColumn,

    'headerRowOptions' => ['class' => 'kartik-sheet-style'],

    'filterRowOptions' => ['class' => 'kartik-sheet-style'],

    'export' => [

        'fontAwesome' => true

    ],

    'bordered' => true,

    'striped' => true,

    'condensed' => true,

    'responsive' => true,

    'hover' => true,

    'showPageSummary' => false,

    'panel' => [

        'type' => GridView::TYPE_SUCCESS,

        "heading" => "<h3 class='panel-title'><i class='glyphicon glyphicon-globe'></i> " . $this->title . "</h3>",

    ],

    'persistResize' => false,

    'toggleDataOptions' => ['minCount' => 10],

    'exportConfig' => true,

]);

?>

<?=

GridView::widget([

    'dataProvider' => $dataProvider_telefon,

    'filterModel' => $searchModel_telefon,

    'columns' => $gridColumn_telefon,

    'headerRowOptions' => ['class' => 'kartik-sheet-style'],

    'filterRowOptions' => ['class' => 'kartik-sheet-style'],

    'export' => [

        'fontAwesome' => true

    ],

    'bordered' => true,

    'striped' => true,

    'condensed' => true,

    'responsive' => true,

    'hover' => true,

    'showPageSummary' => false,

    'panel' => [

        'type' => GridView::TYPE_SUCCESS,

        "heading" => "<h3 class='panel-title'><i class='glyphicon glyphicon-globe'></i> " . $this->title . "</h3>",

    ],

    'persistResize' => false,

    'toggleDataOptions' => ['minCount' => 10],

    'exportConfig' => true,

]);

Pjax::end();

?>[/color][/font]

[font="Arial, sans-serif"][color="#0c0c0c"]

[/color][/font]

[font="Arial, sans-serif"] [/font]

[font="Arial, sans-serif"][color="#0c0c0c"]Controller[/color][/font]

[font="Arial, sans-serif"][color="#0c0c0c"]


[/color][/font]

[font="Arial, sans-serif"][color="#0c0c0c"]

    public function actionIndex() {

        $searchModel = new KontaktAdresseSearch();

        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        $searchModel_telefon = new KontaktTelefonSearch();

        $dataProvider_telefon = $searchModel_telefon->search(Yii::$app->request->queryParams);


        return $this->render('index', [

                    'searchModel' => $searchModel,

                    'dataProvider' => $dataProvider,

                    'dataProvider_telefon' => $dataProvider_telefon,

                    'searchModel_telefon' => $searchModel_telefon

        ]);

    }[/color][/font]

[font="Arial, sans-serif"][color="#0c0c0c"]

[/color][/font]

Thx both for ur help. This thread can be closed as sucessfully solved