示例#1
0
 public function actionCreate()
 {
     $response = ['action' => 'reload-page', 'form' => ''];
     $request = Yii::$app->request;
     $model = new Campaign();
     $model->loadDefaultValues();
     if ($request->isAjax && $request->isPost) {
         if ($model->load($request->post())) {
             $model->startDate = isset($model->startDate) ? date('U', strtotime($model->startDate)) : null;
             $model->endDate = isset($model->endDate) ? date('U', strtotime($model->endDate)) : null;
             $model->save();
             return $response;
         }
     }
     $code = Yii::$app->request->get('code');
     $form = Yii::$app->controller->renderPartial('@frontend/views/campaign/_form', ['model' => $model, 'code' => $code], true);
     return ['action' => 'create', 'form' => $form];
 }
示例#2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CampaignModel::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'thumbnail', $this->thumbnail]);
     return $dataProvider;
 }
 /**
  * Finds the Campaign model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Campaign the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Campaign::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCampaigns()
 {
     return $this->hasMany(Campaign::className(), ['id' => 'campaign_id'])->viaTable('{{%video_campaign}}', ['video_id' => 'id']);
 }
示例#5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCampaign()
 {
     return $this->hasOne(Campaign::className(), ['id' => 'campaign_id']);
 }