Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.93 KB | None | 0 0
  1. <?php
  2.  
  3. class LinkController extends RController
  4. {
  5.     /**
  6.     * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
  7.     * using two-column layout. See 'protected/views/layouts/column2.php'.
  8.     */
  9.     public $layout='application.modules.admin.views.layouts.column2';
  10.  
  11.     /**
  12.     * @return array action filters
  13.     */
  14.     public function filters()
  15.     {
  16.         return array(
  17.             'rights',
  18.                         //'accessControl', // perform access control for CRUD operations
  19.             //'postOnly + delete', // we only allow deletion via POST request
  20.         );
  21.     }
  22.  
  23.     /**
  24.     * Specifies the access control rules.
  25.     * This method is used by the 'accessControl' filter.
  26.     * @return array access control rules
  27.     */
  28.     public function accessRules()
  29.     {
  30.     return array(
  31.     array('allow',  // allow all users to perform 'index' and 'view' actions
  32.     'actions'=>array('index','view'),
  33.     'users'=>array('*'),
  34.     ),
  35.     array('allow', // allow authenticated user to perform 'create' and 'update' actions
  36.     'actions'=>array('create','update'),
  37.     'users'=>array('@'),
  38.     ),
  39.     array('allow', // allow admin user to perform 'admin' and 'delete' actions
  40.     'actions'=>array('admin','delete'),
  41.     'users'=>array('admin'),
  42.     ),
  43.     array('deny',  // deny all users
  44.     'users'=>array('*'),
  45.     ),
  46.     );
  47.     }
  48.  
  49.     /**
  50.     * Displays a particular model.
  51.     * @param integer $id the ID of the model to be displayed
  52.     */
  53.     public function actionView($id)
  54.     {
  55.         $this->layout = '//layouts/main';
  56.         $this->render('view',array(
  57.             'model'=>$this->loadModel($id),
  58.         ));
  59.     }
  60.  
  61.     /**
  62.     * Creates a new model.
  63.     * If creation is successful, the browser will be redirected to the 'view' page.
  64.     */
  65.     public function actionCreate()
  66.     {
  67.         $model=new Link;
  68.  
  69.         // Uncomment the following line if AJAX validation is needed
  70.         // $this->performAjaxValidation($model);
  71.  
  72.         if(isset($_POST['Link']))
  73.         {
  74.             $model->attributes=$_POST['Link'];
  75.             if($model->save())
  76.                 $this->redirect(array('admin'));
  77.         }
  78.  
  79.         $this->render('create',array(
  80.         'model'=>$model,
  81.         ));
  82.     }
  83.  
  84.     /**
  85.     * Updates a particular model.
  86.     * If update is successful, the browser will be redirected to the 'view' page.
  87.     * @param integer $id the ID of the model to be updated
  88.     */
  89.     public function actionUpdate($id)
  90.     {
  91.         $model=$this->loadModel($id);
  92.  
  93.         // Uncomment the following line if AJAX validation is needed
  94.         // $this->performAjaxValidation($model);
  95.  
  96.         if(isset($_POST['Link']))
  97.         {
  98.         $model->attributes=$_POST['Link'];
  99.         if($model->save())
  100.         $this->redirect(array('admin'));
  101.         }
  102.  
  103.         $this->render('update',array(
  104.         'model'=>$model,
  105.         ));
  106.     }
  107.  
  108.     /**
  109.     * Deletes a particular model.
  110.     * If deletion is successful, the browser will be redirected to the 'admin' page.
  111.     * @param integer $id the ID of the model to be deleted
  112.     */
  113.     public function actionDelete($id)
  114.     {
  115.     if(Yii::app()->request->isPostRequest)
  116.     {
  117.     // we only allow deletion via POST request
  118.     $this->loadModel($id)->delete();
  119.  
  120.     // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
  121.     if(!isset($_GET['ajax']))
  122.     $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
  123.     }
  124.     else
  125.     throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
  126.     }
  127.  
  128.     /**
  129.     * Lists all models.
  130.     */
  131.     public function actionIndex()
  132.     {
  133.         $this->layout = '//layouts/column2';
  134.         $model=new Link('search');
  135.         $model->unsetAttributes();  // clear any default values
  136.  
  137.         if(isset($_GET['Link']))
  138.             $model->attributes=$_GET['Link'];
  139.         $this->render('index',array(
  140.             'model'=>$model,
  141.         ));
  142.     }
  143.  
  144.     /**
  145.     * Manages all models.
  146.     */
  147.     public function actionAdmin()
  148.     {
  149.         $model=new Link('search');
  150.         $model->unsetAttributes();  // clear any default values
  151.         if(isset($_GET['Link']))
  152.             $model->attributes=$_GET['Link'];
  153.  
  154.         $this->render('admin',array(
  155.             'model'=>$model,
  156.         ));
  157.     }
  158.  
  159.     /**
  160.     * Returns the data model based on the primary key given in the GET variable.
  161.     * If the data model is not found, an HTTP exception will be raised.
  162.     * @param integer the ID of the model to be loaded
  163.     */
  164.     public function loadModel($id)
  165.     {
  166.         $model=Link::model()->findByPk($id);
  167.         if($model===null)
  168.             throw new CHttpException(404,'The requested page does not exist.');
  169.         return $model;
  170.     }
  171.  
  172.     /**
  173.     * Performs the AJAX validation.
  174.     * @param CModel the model to be validated
  175.     */
  176.     protected function performAjaxValidation($model)
  177.     {
  178.         if(isset($_POST['ajax']) && $_POST['ajax']==='link-form')
  179.         {
  180.             echo CActiveForm::validate($model);
  181.             Yii::app()->end();
  182.         }
  183.     }
  184. }
  185.  
  186.  
  187. <?php
  188. $this->breadcrumbs=array(
  189.     'Links'=>array('index'),
  190.     'Manage',
  191. );
  192.  
  193. $this->menu=array(
  194. array('label'=>'List Link','url'=>array('index')),
  195. array('label'=>'Create Link','url'=>array('create')),
  196. );
  197.  
  198. ?>
  199.  
  200. <div class="page-header">
  201.     <h3>Менеджер Ссылок</h3>
  202. </div>
  203.  
  204.  
  205. <?php $this->widget('bootstrap.widgets.TbGridView',array(
  206. 'id'=>'link-grid',
  207. 'dataProvider'=>$model->searchIndex(),
  208. 'filter'=>$model,
  209. 'type'=>'striped bordered condensed',
  210. 'template'=>'{items}{pager}<br>{summary}',
  211. 'columns'=>array(
  212.         'id',
  213.         'title',
  214.         'link',
  215.         array(
  216.                     'name'=>'category_id',
  217.                     'type'=>'raw',
  218.                     'value'=>'$data->linkcategorys->title'
  219.                 ),
  220. array(
  221. 'class'=>'bootstrap.widgets.TbButtonColumn',
  222. ),
  223. ),
  224. )); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement