protected function findModel($id)
 {
     if (($model = Course::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionRegister($co = null, $cl = null)
 {
     $model = new Student();
     if ($model->load(Yii::$app->request->post())) {
         $model->course_id = $co;
         $model->classid = $cl;
         $model->created_dt = date('Y-m-d H:i:s');
         $model->save();
         return $this->redirect(['success']);
         //return $this->redirect(['view', 'id' => $model->id]);
     } else {
         if (!empty($co)) {
             $courselist = Course::findOne($co);
         }
         return $this->render('register', ['model' => $model, 'courselist' => $courselist]);
     }
 }
Beispiel #3
0
<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use app\models\User;
use app\models\Course;
/* @var $this yii\web\View */
/* @var $model app\models\UserHasCourse */
$this->title = $model->user_id;
$this->params['breadcrumbs'][] = ['label' => 'User Has Courses', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-has-course-view">
    <?php 
echo DetailView::widget(['model' => $model, 'attributes' => [['label' => 'User', 'value' => User::findOne($model->user_id)->first_name . ' ' . User::findOne($model->user_id)->last_name . ' ( ' . User::findOne($model->user_id)->username . ' )'], ['label' => 'Course', 'value' => Course::findOne($model->course_id)->code . ' ( ' . Course::findOne($model->course_id)->name . ' )']]]);
?>

    <p>
        <?php 
echo Html::a('Update', ['update', 'user_id' => $model->user_id, 'course_id' => $model->course_id], ['class' => 'btn btn-primary']);
?>
        <?php 
echo Html::a('Delete', ['delete', 'user_id' => $model->user_id, 'course_id' => $model->course_id], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Are you sure you want to delete this item?', 'method' => 'post']]);
?>
    </p>
</div>
 /**
  * Show the student assistant picking page
  *
  * @param $model
  * @param $course_id
  * @return string
  */
 private function _pickStudentAssistant($model, $course_id)
 {
     // Fetch all students assistants
     $course = Course::findOne($course_id);
     return $this->render('pickSA', ['model' => $model, 'sas' => $course->studentAssistants]);
 }