Commit db7907b1 authored by Shakarim Sapa's avatar Shakarim Sapa

- Added copy action

parent 34cd760b
...@@ -8,11 +8,12 @@ ...@@ -8,11 +8,12 @@
namespace common\modules\cases\controllers; namespace common\modules\cases\controllers;
use common\modules\content\models\CoContent;
use Yii; use Yii;
use yii\filters\VerbFilter;
use yii\web\NotFoundHttpException;
use common\components\AdminController; use common\components\AdminController;
use common\modules\content\models\CoContent;
use common\modules\content\models\SearchCoContent; use common\modules\content\models\SearchCoContent;
use yii\filters\VerbFilter;
class CasesAdminController extends AdminController { class CasesAdminController extends AdminController {
public static function actionsTitles(){ public static function actionsTitles(){
...@@ -98,4 +99,61 @@ class CasesAdminController extends AdminController { ...@@ -98,4 +99,61 @@ class CasesAdminController extends AdminController {
'id' => 4 'id' => 4
]); ]);
} }
public function actionCopy($id)
{
$model = $this->findModel($id);
$model->url = null;
Yii::$app->controller->page_title = 'Копирование страницы';
Yii::$app->controller->breadcrumbs = [
['Управление контентом' => \yii\helpers\Url::toRoute('manage')],
$model->url,
];
if (Yii::$app->request->isPost)
{
$transaction = Yii::$app->db->beginTransaction();
try
{
$model = new CoContent;
$model->attributes = Yii::$app->request->post('CoContent');
if($model->save())
{
$transaction->commit();
return $this->redirect(['manage']);
}
}
catch (\Exception $e)
{
$transaction->rollBack();
throw $e;
}
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Finds the CoContent model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return CoContent the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = CoContent::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
} }
\ 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