Commit 5485e6a9 authored by Shakarim Sapa's avatar Shakarim Sapa

- Добавлен метод редактирования курсов;

- Добавлен метод возвращающий модель курсов;
parent daa3f9bf
<?php
/**
* Created by PhpStorm.
* User: PHOENIX
* Date: 10.04.16
* Time: 14:06
*/
namespace common\modules\analyticsSchool\controllers;
use common\components\AdminController;
use common\modules\analyticsSchool\models\AnalyticsSchoolCourse;
use yii\data\ActiveDataProvider;
use yii\web\NotFoundHttpException;
class CourseAdminController extends AdminController {
/**
......@@ -20,7 +13,8 @@ class CourseAdminController extends AdminController {
public static function actionsTitles(){
return [
'Manage' => 'Управление курсами',
'Create' => 'Добавление нового курса'
'Create' => 'Добавление нового курса',
'Update' => 'Редактирование курса'
];
}
......@@ -40,6 +34,9 @@ class CourseAdminController extends AdminController {
);
}
/**
* @return string|\yii\web\Response
*/
public function actionCreate(){
$model = new AnalyticsSchoolCourse();
if ($model->load(\Yii::$app->request->post())) {
......@@ -56,4 +53,40 @@ class CourseAdminController extends AdminController {
]
);
}
/**
* @param $id
* @return string|\yii\web\Response
*/
public function actionUpdate($id){
/** @var AnalyticsSchoolCourse $model */
$model = self::findModel($id);
if ($model->load(\Yii::$app->request->post())) {
if ($model->validate() && $model->save())
return $this->redirect([
'manage'
]);
}
$form = new \common\components\BaseForm('/common/modules/analyticsSchool/forms/CourseForm', $model);
return $this->render(
'update',
[
'form' => $form
]
);
}
/**
* @param $id
* @return AnalyticsSchoolCourse|null
* @throws NotFoundHttpException
*/
public function findModel($id)
{
if (($model = AnalyticsSchoolCourse::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
\ No newline at end of file
<?= $form->out;
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment