/** * Finds the TypePlant model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return TypePlant the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = TypePlant::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
?> </h3> </div> <div class="panel-body"> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('<span class=\'glyphicon glyphicon-plus-sign\'></span> ' . Yii::t('app', 'Create'), ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'type_plant_id', 'format' => 'raw', 'value' => function ($data) { if ($data->type_plant_id > 0) { return \app\models\TypePlant::findOne($data->type_plant_id)->name; } else { return "-"; } }], 'name', 'sort', ['attribute' => 'updated_at', 'headerOptions' => ['style' => 'width:125px;', 'class' => 'text-center'], 'contentOptions' => ['class' => 'text-center'], 'filter' => false, 'format' => ['date', 'php:d/m/y H:i']], ['attribute' => 'updated_by', 'headerOptions' => ['style' => 'width:100px;', 'class' => 'text-center'], 'contentOptions' => ['class' => 'text-center'], 'filter' => false, 'value' => function ($data) { return @\app\models\User::findOne($data->updated_by)->username; }], ['class' => 'yii\\grid\\ActionColumn', 'header' => 'Actions', 'headerOptions' => ['style' => 'width:100px;', 'class' => 'text-center'], 'contentOptions' => ['class' => 'text-center']]]]); ?> </div> </div> </div>
/** * Updates an existing HarvestPlant 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); $typePlant = null; if ($model->plant_id > 0) { $plant = Plant::findOne($model->plant_id); $typePlant = TypePlant::findOne($plant->type_plant_id); } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'typePlant' => $typePlant]); } }