/** * Finds the Tools model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Tools the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Tools::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<?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 $state_id = Yii::$app->user->identity->state_id; $columns[] = ['class' => 'yii\\grid\\SerialColumn']; $columns[] = ['attribute' => 'tools_id', 'format' => 'raw', 'value' => function ($data) { if ($data->tools_id > 0) { return \app\models\Tools::findOne($data->tools_id)->name; } else { return "-"; } }]; if ($state_id > 0) { } else { $columns[] = ['attribute' => 'state_id', 'format' => 'raw', 'value' => function ($data) { if ($data->state_id > 0) { return \app\models\State::findOne($data->state_id)->name; } else { return "-"; } }]; } $columns[] = ['attribute' => 'year', 'headerOptions' => ['style' => 'width:75px;', 'class' => 'text-center'], 'contentOptions' => ['class' => 'text-center']];
/** * 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]); } }