/**
  * 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]);
     }
 }
Exemple #2
0
 /**
  * Finds the Plant model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Plant the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Plant::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #3
0
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a(Yii::t('app', '<span class=\'glyphicon glyphicon-plus-sign\'></span>  Create Harvest Plant'), ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
$state_id = Yii::$app->user->identity->state_id;
$columns[] = ['class' => 'yii\\grid\\SerialColumn'];
$columns[] = ['attribute' => 'plant_id', 'format' => 'raw', 'value' => function ($data) {
    if ($data->plant_id > 0) {
        return \app\models\Plant::findOne($data->plant_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']];