public function actionUpdate($slug)
 {
     $model = $this->findModel($slug);
     if (!Yii::$app->user->can('editNews', ['model' => $model])) {
         $this->redirect('/news');
     }
     if ($model->load(Yii::$app->request->post())) {
         //!!! сделать поле status unsafe
         if (!Yii::$app->user->can('setStatusActiveNews')) {
             $model->status = 0;
         }
         if ($model->save()) {
             return $this->redirect(['view', 'slug' => $model->slug]);
         }
     }
     return $this->render('update', ['model' => $model, 'category' => ArrayHelper::map(Category::find()->all(), 'id', 'title')]);
 }
 public function actionImg()
 {
     $categories = Category::find()->all();
     $uploadModel = new UploadForm();
     return $this->render("save", ['categories' => $categories, 'uploadModel' => $uploadModel]);
 }
Example #3
0
use yii\bootstrap\Nav;
use yii\helpers\Html;
use app\models\entity\Category;
$this->beginContent('@app/views/layouts/main.php');
?>
<div class="container">
	<div class="col-xs-12 col-sm-2">
		<p>
			<h2>News</h2>
			<?php 
$items = [['label' => 'All', 'url' => ['/news/default/index', 'category' => 'all']]];
if (!Yii::$app->user->isGuest) {
    $items[] = ['label' => 'My', 'url' => ['/news/default/index', 'category' => 'my']];
}
$category = Category::find()->all();
foreach ($category as $c) {
    $items[] = ['label' => $c->title, 'url' => ['/news/default/index', 'category' => $c->slug]];
}
?>
			<?php 
echo Nav::widget(['items' => $items, 'options' => ['class' => 'nav-pills nav-stacked']]);
?>
		</p>
		<?php 
if (!Yii::$app->user->isGuest) {
    ?>
		<p><?php 
    echo Html::a('Create news', ['create'], ['class' => 'btn btn-success']);
    ?>
</p>