0
GridProのデータを表示するためにdataProviderのためにjsonを使うのが熱いYii2?ここでdataProviderのためのJsonの使い方Yii2
は私のコントローラ(Yii2ジェネレータからコードを生成)コードされています
<?php
namespace app\controllers;
use Yii;
use app\models\Users;
use app\models\UsersSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* UsersController implements the CRUD actions for Users model.
*/
class UsersController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all Users models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new UsersSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Users model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new Users model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Users();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing Users model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing Users model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the Users model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Users the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Users::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
とインデックスの私のGridViewのは、このようなものです:
<?php
use yii\helpers\Html;
use kartik\grid\GridView;
use yii\widgets\ActiveForm;
use yii\widgets\Pjax;
use yii\web\JsExpression;
/* @var $this yii\web\View */
/* @var $searchModel app\models\SalesOrderSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
?>
<div class="start-stock-index">
<div class="form-group">
<?= Html::a('Create Customer', ['create'], ['class' => 'btn btn-success']) ?>
</div>
<?php Pjax::begin(); ?>
<?= GridView::widget([
'dataProvider'=>$dataProvider,
'filterModel'=>$searchModel,
'showPageSummary'=>true,
'pjax'=>true,
'striped'=>true,
'hover'=>true,
'responsiveWrap' => false,
'panel'=>['type'=>'primary', 'heading'=>$partner_name],
'columns'=>[
[
'attribute' => 'cust_name',
'value' => 'cust_name',
'label' => 'Name',
'contentOptions' =>
['style'=>'max-width: 100px; font-size: 12px;overflow: auto; word-wrap: break-word;'],
],
[
'attribute' => 'phone_number',
'value' => 'phone_number',
'label' => 'Phone Number',
'contentOptions' =>
['style'=>'max-width: 100px; font-size: 12px;overflow: auto; word-wrap: break-word;'],
],
[
'attribute' => 'age_type',
'value' => 'ageType.age_name',
'label' => 'Age Category',
'contentOptions' =>
['style'=>'max-width: 100px; font-size: 12px;overflow: auto; word-wrap: break-word;'],
],
['class' => 'kartik\grid\ActionColumn','template' => '{update} {delete}',],
],
]); ?>
<?php Pjax::end(); ?>
</div>
<?php
$script = <<< JS
JS;
$this->registerJs($script);
?>
私が欲しいものは、番組データであるJSONからなるようにそれは安らかなページにすることができます。ありがとう。
としてヘルパーを使用することができます使用をJSONデータをCONVERできarrayDataProvider のために右であります解決された??答えは下でしょうか? – Goli