コード例 #1
0
 public function actionIndex()
 {
     $this->partner_id = Yii::app()->params['partner_id'];
     $file = dirname(__FILE__) . '/../../../../common/config/contacts.php';
     if (!is_file($file)) {
         throw new CHttpException(404, 'Файл контактов не найден' . $file);
     }
     $content = file_get_contents($file);
     $arr = json_decode($content, true);
     $partnerModel = Partners::model()->findByPk($this->partner_id);
     if ($partnerModel == NULL) {
         throw new CHttpException(404, 'Указанная запись не найдена');
     }
     $model = new ContactForm();
     $model->setAttributes($arr);
     if (isset($_POST['Partners']) || isset($_POST['ContactForm'])) {
         $partnerModel->attributes = $_POST['Partners'];
         $partnersuccess = $partnerModel->validate();
         if ($partnersuccess) {
             $partnerModel->update();
         }
         $config = array('vk' => $_POST['ContactForm']['vk'], 'twitter' => $_POST['ContactForm']['twitter'], 'facebook' => $_POST['ContactForm']['facebook'], 'odnokl' => $_POST['ContactForm']['odnokl']);
         $model->setAttributes($config);
         $confsuccess = $model->validate();
         if ($confsuccess) {
             $str = json_encode($config);
             file_put_contents($file, $str);
         }
         if ($partnersuccess && $confsuccess) {
             Yii::app()->user->setFlash('config', Yii::t('main', 'Your new options have been saved.'));
         }
     }
     $this->render('index', array('model' => $model, 'partnerModel' => $partnerModel));
 }
コード例 #2
0
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     $model = Partners::model()->with(array('portfolio' => array('with' => 'photos')))->findByPk($id);
     $model->deletePartners();
     // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
     if (!isset($_GET['ajax'])) {
         $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
     }
 }
コード例 #3
0
 public function loadModel($id)
 {
     $model = Partners::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }