public function getEducation() { return $this->hasMany(Education::className(), ['user_id' => 'id']); }
public function actionEducation() { $userdetails = \Yii::$app->user->identity; $model = Education::find()->where(['user_id' => $userdetails->id])->one(); if (empty($model)) { $model = new Education(); } $userprofile = UserProfile::find()->where(['user_id' => $userdetails->id])->one(); if (empty($userprofile)) { $userprofile = new UserProfile(); } $user = Userform::find()->where(['id' => $userdetails->id])->one(); if (empty($user)) { $user = new Userform(); } //echo "<pre>";print_r($user->competitiveExamDestails);die; if (isset($_POST['Education'])) { $model->attributes = $_POST['Education']; $model->user_id = $userdetails->id; $model->course_name = $_POST['Education']['course_name']; $model->branch = $_POST['Education']['course_name']; $model->school_college = $_POST['Education']['school_college']; $model->university_board = $_POST['Education']['university_board']; $model->is_passed = $_POST['Education']['is_passed']; $model->backlog = $_POST['Education']['backlog']; $model->total_marks = $_POST['Education']['total_marks']; $model->obtained_marks = $_POST['Education']['obtained_marks']; $attend_date = explode('/', $_POST['Education']['attend_date']); $model->attend_date = $attend_date[2] . '-' . $attend_date[1] . '-' . $attend_date[0]; $passing_year = explode('/', $_POST['Education']['passing_year']); $model->passing_year = $passing_year[2] . '-' . $passing_year[1] . '-' . $passing_year[0]; $model->description = $_POST['Education']['description']; if ($model->validate()) { if (isset($_POST['isnew'])) { \Yii::$app->db->createCommand()->insert('tlb_education', ['course_name' => $model->course_name, 'branch' => $model->branch, 'school_college' => $model->school_college, 'university_board' => $model->university_board, 'is_passed' => $model->is_passed, 'backlog' => $model->backlog, 'total_marks' => $model->total_marks, 'obtained_marks' => $model->obtained_marks, 'attend_date' => $model->attend_date, 'passing_year' => $model->passing_year, 'description' => $model->description, 'created' => new \yii\db\Expression('NOW()'), 'user_id' => $userdetails->id])->execute(); } else { $model->save(); } \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ['data' => $model]; } } return $this->render('education', ['model' => $model, 'user' => $user, 'userprofile' => $userprofile]); }
<?php echo $form->field($model, 'institution_location')->textarea(['rows' => 6]); ?> <?php echo $form->field($model, 'from_date')->input('date'); ?> <?php echo $form->field($model, 'to_date')->input('date'); ?> </div> <div class="col-md-6"> <?php echo $form->field($model, 'graduated_status')->dropDownList(Education::getListGraduateStatus()); ?> <?php echo $form->field($model, 'gpa')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'gpa_max')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'description')->textarea(['rows' => 6]); ?> </div> </div>
use yii\helpers\Html; use yii\widgets\DetailView; use common\models\Education; /* @var $this yii\web\View */ /* @var $model common\models\EducationCrud */ $this->title = 'View :' . $model->institution_name; $this->params['breadcrumbs'][] = ['label' => 'Educations', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="education-crud-view"> <h1><?php echo Html::encode($this->title); ?> </h1> <p> <?php echo Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']); ?> <?php echo Html::a('Delete', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Are you sure you want to delete this item?', 'method' => 'post']]); ?> </p> <?php echo DetailView::widget(['model' => $model, 'attributes' => ['institution_name', 'institution_type', 'institution_location:ntext', 'from_date:date', 'to_date:date', ['label' => 'asd', 'value' => Education::getGraduateStatusName($model->graduated_status)], 'gpa', 'gpa_max', 'description:ntext']]); ?> </div>
?> <div class="education-crud-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Add Education', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php Pjax::begin(); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'institution_name', 'institution_type', 'institution_location:ntext', 'from_date:date', 'to_date:date', ['attribute' => 'graduated_status', 'value' => function ($model) { return Education::getGraduateStatusName($model->graduated_status); }], 'gpa', 'gpa_max', 'description:ntext', ['class' => 'yii\\grid\\ActionColumn']]]); ?> <?php Pjax::end(); ?> </div>