public function actionUpload($id) { $fileName = 'file'; // $uploadPath = 'upload/hrd/Employee'; $model = new Termgeneral(); if (isset($_FILES[$fileName])) { $file = \yii\web\UploadedFile::getInstanceByName($fileName); $data = $this->saveimage(file_get_contents($file->tempName)); $model->ID_TERM = $id; $model->ISI_TERM = $data; if ($model->save()) { //Now save file data to database echo \yii\helpers\Json::encode($file); } } return false; }
public function searchtermgeneral($params, $id) { $query = Termgeneral::find()->where(['ID_TERM' => $id]); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['ID' => $this->ID, 'STATUS' => $this->STATUS, 'CREATE_AT' => $this->CREATE_AT, 'UPDATE_AT' => $this->UPDATE_AT]); $query->andFilterWhere(['like', 'SUBJECT', $this->SUBJECT])->andFilterWhere(['like', 'ISI_TERM', $this->ISI_TERM])->andFilterWhere(['like', 'CREATE_BY', $this->CREATE_BY])->andFilterWhere(['like', 'UPDATE_BY', $this->UPDATE_BY]); return $dataProvider; }
/** * Finds the Termgeneral model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Termgeneral the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Termgeneral::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; use lukisongroup\master\models\Termgeneral; use kartik\widgets\Select2; /* @var $this yii\web\View */ /* @var $model lukisongroup\master\models\Termgeneral */ /* @var $form yii\widgets\ActiveForm */ $data = Termgeneral::find()->all(); $to = "ID"; $from = "SUBJECT"; ?> <div class="termgeneral-form"> <?php $form = ActiveForm::begin(['id' => $model->formName()]); ?> <?php echo $form->field($model, 'GENERAL_TERM')->widget(Select2::classname(), ['options' => ['placeholder' => 'Select ...'], 'data' => $model->data($data, $to, $from)]); ?> <!-- $form->field($model, 'ISI_TERM')->textarea(['rows' => 6]) ?> --> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
public function getGeneral() { # code... return $this->hasOne(Termgeneral::className(), ['ID' => 'GENERAL_TERM']); }