public function actionView($type, $alias)
 {
     $item = Article::find()->type($type)->alias($alias)->one();
     if (!$item) {
         throw new HttpException(404, 'Статья не найдена');
     }
     return $this->render('view', ['item' => $item, 'type' => $type]);
 }
 /**
  * Finds the Article model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Article the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Article::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Article::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'type' => $this->type, 'visible' => $this->visible, 'dateCreate' => $this->dateCreate]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'alias', $this->alias]);
     return $dataProvider;
 }
Exemplo n.º 4
0
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel app\modules\cms\models\ArticleSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('app', 'Статьи');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="article-index">


    <pre>Ссылка на модуль: <?php 
echo htmlspecialchars('<?=\\yii\\helpers\\Url::to(["/cms/article/list","type"=>"(news|article|stock)"])?>');
?>
</pre>


    <p>
        <?php 
echo Html::a(Yii::t('app', 'Добавить статью'), ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['header' => '', 'value' => function ($model) {
    return Html::img($model->image->resize('100x100'));
}, 'format' => 'html'], 'title', ['attribute' => 'type', 'filter' => \app\modules\cms\models\Article::typeList(), 'value' => 'typeView'], 'alias', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}']]]);
?>

</div>
Exemplo n.º 5
0
 public function type($type)
 {
     $typeId = Article::getTypeIdByAlias($type);
     $this->where(['type' => $typeId]);
     return $this;
 }
Exemplo n.º 6
0
<div class="article-form">

    <?php 
$form = ActiveForm::begin();
?>


    <div class="row">
        <div class="col-md-1">
            <?php 
echo $form->field($model, 'visible')->checkbox(['label' => 'Активен']);
?>
        </div>
        <div class="col-md-6">
            <?php 
echo $form->field($model, 'type')->dropDownList(\app\modules\cms\models\Article::typeList(), ['prompt' => 'Выбор']);
?>
        </div>
        <div class="col-md-5">
            <?php 
echo $form->field($model, 'dateCreate')->widget(\yii\jui\DatePicker::className(), ['dateFormat' => 'yyyy-MM-dd', 'options' => ['class' => 'form-control']]);
?>
        </div>
    </div>

    <div class="row">
        <div class="col-md-6">
            <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => 128]);
?>
        </div>
Exemplo n.º 7
0
                <li><a href="<?php 
echo \yii\helpers\Url::to(["/cms/article/list", "type" => "news"]);
?>
">НОВОСТИ</a></li>
                <li ><a href="<?php 
echo \yii\helpers\Url::to(["/cms/article/list", "type" => "stock"]);
?>
" class="active_dp">АКЦИИ</a></li>
                <li><a href="<?php 
echo \yii\helpers\Url::to(["/cms/article/list", "type" => "article"]);
?>
">ПОЛЕЗНАЯ ИНФОРМАЦИЯ</a></li>
            </ul>
        </div>
        <?php 
if ($items = \app\modules\cms\models\Article::getAllByCategory('stock')) {
    ?>
        <div id="hWrapper">
            <div id="carouselh" >
                <?php 
    foreach ($items as $item) {
        ?>
                <div class="news">
                    <a href="<?php 
        echo $item->getPath();
        ?>
">
                        <div class="news_img">
                            <img alt="" src="<?php 
        echo $item->image->resize('230x119', \alexBond\thumbler\Thumbler::METHOD_CROP_CENTER);
        ?>