Beispiel #1
0
 public function actionSubscribe()
 {
     $model = new Subscribers();
     if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->save()) {
             return 'Спасибо. На указанный email оформлена подписка на новости института.';
         } else {
             return 'Возникла ошибка оформления подписки. Попробуйте позднее.';
         }
     } else {
         $errors = $model->errors[email];
         return $errors[0];
     }
 }
Beispiel #2
0
 /**
  * Finds the Subscribers model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Subscribers the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Subscribers::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Subscribers::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'email', $this->email]);
     return $dataProvider;
 }
Beispiel #4
0
<?php

use yii\helpers\Html;
use yii\grid\GridView;
use backend\modules\subscribers\models\Subscribers;
/* @var $this yii\web\View */
/* @var $searchModel backend\modules\subscribers\models\SubscribersSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Подписчики';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="box box-primary">
    <div class="box-body">

        <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>
    
        <p>
            <?php 
echo Html::a('Добавить подписчика', ['create'], ['class' => 'btn btn-success']);
?>
        </p>
        <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'email:email', 'created_at:date', 'updated_at:date', ['attribute' => 'status', 'filter' => Subscribers::getTypeArray(), 'value' => 'TypeName'], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}', 'contentOptions' => ['class' => 'actionColumn'], 'buttonOptions' => ['class' => 'btn btn-sm btn-default', 'style' => 'padding:1px 10px;']]]]);
?>
        
    </div>
</div>
Beispiel #5
0
/* @var $model backend\modules\subscribers\models\Subscribers */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="box box-primary">
    <div class="box-body">

        <?php 
$form = ActiveForm::begin();
?>
    
        <?php 
echo $form->field($model, 'email')->textInput(['maxlength' => true]);
?>
        <?php 
echo $form->field($model, 'status')->dropDownlist(Subscribers::getTypeArray());
?>
    
        <div class="form-group">
            <?php 
echo Html::submitButton($model->isNewRecord ? 'Добавить' : 'Обновить', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
        </div>
    
        <?php 
ActiveForm::end();
?>
    
    </div>
</div>