/** * Updates an existing HarvestTools 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); $typeTools = null; if ($model->tools_id > 0) { $tools = Tools::findOne($model->tools_id); $typeTools = TypeTools::findOne($tools->type_tools_id); } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'typeTools' => $typeTools]); } }
?> </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_tools_id', 'format' => 'raw', 'value' => function ($data) { if ($data->type_tools_id > 0) { return \app\models\TypeTools::findOne($data->type_tools_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>
/** * Finds the TypeTools model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return TypeTools the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = TypeTools::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }