PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 8, 2022

[FIXED] how to access data array data provider yii2?

 March 08, 2022     arrays, frameworks, php, yii, yii2     No comments   

Issue

i have used ArrayDataProvider in controller yii2.

<?php

public function actionPagination_product2(){
$tb_tab=Tablet::tableName();
Digital.inner_memory')->asArray()->all();
$data = Digital::find()->joinWith('tablet',true,'Left Join')->where('Tablet.sup_id = Digital.id')->asArray()->all();
$dataProvider = new ArrayDataProvider([
    'allModels' => $data,
	 'sort' => [
        'attributes' => ['id'],
    ],
    'pagination' => [
        'pageSize' => 20,
    ],
]);

   return $this->render('pagination_pro2', [
      'dataProvider' => $dataProvider,
   ]);
   
   ?>

and in view pagination_pro2 i have

<?php
   use yii\widgets\ListView;
   echo ListView::widget([
      'dataProvider' => $dataProvider,
	 
      'itemView' => '_page1',
   ]);
?>

and in view _page1 i have

<?php
   use yii\helpers\Html;
   use yii\helpers\HtmlPurifier;
?>
<div class = "user">


   <?php 
foreach($model as $attribute => $value) {
   // do your stuff here
if(isset($model['sim_num'])){
echo "aaaa";
}
}
?>

</div>

that works true.but i want to access one by one of model attributes.

are that works true? what have to do? tnx


Solution

To access model attributes one by one in view _page1 use foreach loop:

  1. If your data is just array:

    foreach($model as $attribute => $value) {
       // do your stuff here
    }
    
  2. If your array is array of models:

    foreach($model->attributes as $attribute => $value) {
       // do your stuff here
    }
    


Answered By - Yupik
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing