Created
May 23, 2013 16:22
-
-
Save alexbaumgertner/5637334 to your computer and use it in GitHub Desktop.
болванка-контроллер
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/********************************************************************************************** | |
* Easy CMS | |
***********************************************************************************************/ | |
class PhotoalbumsController extends Controller | |
{ | |
/** | |
* @var string the default layout for the views. Defaults to '//layouts/column2', meaning | |
* using two-column layout. See 'protected/views/layouts/column2.php'. | |
*/ | |
public $layout = '//layouts/onecolumn'; | |
/** | |
* @var CActiveRecord the currently loaded data model instance. | |
*/ | |
private $_model; | |
/** | |
* @return array action filters | |
*/ | |
public function filters() | |
{ | |
return array( | |
'accessControl', // perform access control for CRUD operations | |
); | |
} | |
/** | |
* Specifies the access control rules. | |
* This method is used by the 'accessControl' filter. | |
* @return array access control rules | |
*/ | |
public function accessRules() | |
{ | |
return array( | |
array('allow', // allow all users to perform 'index' and 'view' actions | |
'actions' => array('index', 'view'), | |
'users' => array('*'), | |
), | |
array('allow', // allow admin user to perform 'admin' and 'delete' actions | |
'actions' => array('admin', 'delete', 'create', 'update', 'publish', 'unpublish'), | |
'users' => array('demo'), | |
), | |
array('deny', // deny all users | |
'users' => array('*'), | |
), | |
); | |
} | |
/* actions to Views (begin) */ | |
/* index */ | |
public function actionIndex() | |
{ | |
$this->render('index', array()); | |
} | |
/* view */ | |
public function actionView() | |
{ | |
$this->render('view', array( | |
)); | |
} | |
/* admin side (begin) */ | |
/* admin/Photoalbums/index */ | |
public function actionAdmin() | |
{ | |
$this->render('adminIndex', array()); | |
} | |
/* admin/Photoalbums/create */ | |
public function actionCreate() | |
{ | |
$this->render('adminCreate', array( | |
)); | |
} | |
/* admin/Photoalbums/update?id= */ | |
/* | |
* http://5.19.255.134:8111/hunterboat/admin/Photoalbums/update?id=1 | |
*/ | |
public function actionUpdate() | |
{ | |
$this->render('adminUpdate', array()); | |
} | |
/* admin/Photoalbums/delete?id= */ | |
public function actionDelete() | |
{ | |
if (Yii::app()->request->isPostRequest) | |
{ | |
// we only allow deletion via POST request | |
$this->loadModel()->delete(); | |
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser | |
if (!isset($_GET['ajax'])) | |
$this->redirect(array('index')); | |
} else | |
throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); | |
} | |
public function actionPublish() | |
{ | |
$model = $this->loadModel(); | |
$model->published = 1; | |
$model->save(); | |
$this->redirect(array('admin/photoalbums')); | |
} | |
public function actionUnpublish() | |
{ | |
$model = $this->loadModel(); | |
$model->published = 0; | |
$model->save(); | |
$this->redirect(array('admin/photoalbums')); | |
} | |
/* admin side (end) */ | |
/* actions to Views (end) */ | |
/** | |
* 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. | |
*/ | |
public function loadModel() | |
{ | |
if ($this->_model === null) { | |
if (isset($_GET['id'])) | |
$this->_model = Photoalbums::model()->findbyPk($_GET['id']); | |
if ($this->_model === null) | |
throw new CHttpException(404, 'The requested page does not exist.'); | |
} | |
return $this->_model; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment