예제 #1
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Contents::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
예제 #2
0
</div> <!-- END CONTENT -->
</div> <!-- END SUPER -->
<div class="footer-wrap">
	<!-- BEGIN PRE-FOOTER -->
    <div class="pre-footer">
		<div class="container">
			<div class="row">
			<?php 
Yii::import('application.modules.admin.modules.content.models.Contents');
Yii::import('application.modules.admin.modules.content.models.ContentsLang');
$criteria = new CDbCriteria(array('condition' => 'name = :name', 'params' => array('name' => 'Контакты футер'), 'with' => array('lang')));
$content = Contents::model()->find($criteria);
$text = '';
if (!empty($content) && !empty($content->lang)) {
    $text = $content->lang->text;
}
echo $text;
?>
			</div>
		</div>
    </div>
    <!-- END PRE-FOOTER -->
	<!-- BEGIN FOOTER -->
	<div class="footer">
		<div class="container">
			<div class="row">
				<!-- BEGIN COPYRIGHT -->
				<div class="col-md-6 col-sm-6 padding-top-10">
					<?php 
echo date('Y');
?>
예제 #3
0
 public function actionDeleteContent($id)
 {
     if (Yii::app()->request->isPostRequest) {
         if (isset($_POST['YII_CSRF_TOKEN']) && $_POST['YII_CSRF_TOKEN'] === Yii::app()->request->csrfToken) {
             $model = Contents::model()->findByPk($id);
             $page_id = $model->page_id;
             $transaction = Yii::app()->db->beginTransaction();
             try {
                 if (!$model->delete()) {
                     throw new Exception('Ошибка при сохранении данных.');
                 }
                 $criteria = new CDbCriteria();
                 $criteria->condition = 'content_id=:content_id';
                 $criteria->params = array('content_id' => $id);
                 $builder = new CDbCommandBuilder(Yii::app()->db->getSchema());
                 $command = $builder->createDeleteCommand('contents_lang', $criteria);
                 if ($command->execute() === false) {
                     throw new Exception('Ошибка при сохранении данных.');
                 }
                 $transaction->commit();
             } catch (Exception $e) {
                 $transaction->rollBack();
                 echo CJSON::encode(array('error' => $e->getMessage()));
                 Yii::app()->end();
             }
             $this->redirect($this->createUrl('pages/edit/id/' . $page_id));
         }
     } else {
         throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
     }
 }