Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.88 KB | None | 0 0
  1. <?php
  2.  
  3. class TestEmprendimientoController extends Controller
  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='//layouts/column2';
  10.  
  11.     /**
  12.      * @return array action filters
  13.      */
  14.     public function filters()
  15.     {
  16.         return array(
  17.             'accessControl', // perform access control for CRUD operations
  18.         );
  19.     }
  20.  
  21.     /**
  22.      * Specifies the access control rules.
  23.      * This method is used by the 'accessControl' filter.
  24.      * @return array access control rules
  25.      */
  26.     public function accessRules()
  27.     {
  28.         return array(
  29.             array('allow',  // allow all users to perform 'index' and 'view' actions
  30.                 'actions'=>array('index','view'),
  31.                 'users'=>array('*'),
  32.             ),
  33.             array('allow', // allow authenticated user to perform 'create' and 'update' actions
  34.                 'actions'=>array('create','update'),
  35.                 'users'=>array('@'),
  36.             ),
  37.             array('allow', // allow admin user to perform 'admin' and 'delete' actions
  38.                 'actions'=>array('admin','delete'),
  39.                 'users'=>array('admin'),
  40.             ),
  41.             array('deny',  // deny all users
  42.                 'users'=>array('*'),
  43.             ),
  44.         );
  45.     }
  46.  
  47.     /**
  48.      * Displays a particular model.
  49.      * @param integer $id the ID of the model to be displayed
  50.      */
  51.     public function actionView($id)
  52.     {
  53.         $this->render('view',array(
  54.             'model'=>$this->loadModel($id),
  55.         ));
  56.     }
  57.  
  58.     /**
  59.      * Creates a new model.
  60.      * If creation is successful, the browser will be redirected to the 'view' page.
  61.      */
  62.     public function actionCreate()
  63.     {
  64.         $model=new TestEmprendimiento;
  65.                 //$model=new TestEmprendimiento('insert');
  66.                 //$model->setScenario('insert');
  67.                 //$model->scenario = 'insert';
  68.  
  69.         // Uncomment the following line if AJAX validation is needed
  70.         $this->performAjaxValidation($model);
  71.  
  72.         if(isset($_POST['TestEmprendimiento']))
  73.         {
  74.             $model->attributes=$_POST['TestEmprendimiento'];
  75.             if($model->save())
  76.                 $this->redirect(array('view','id'=>$model->id));
  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['TestEmprendimiento']))
  97.         {
  98.             $model->attributes=$_POST['TestEmprendimiento'];
  99.             if($model->save())
  100.                 $this->redirect(array('view','id'=>$model->id));
  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.         $dataProvider=new CActiveDataProvider('TestEmprendimiento');
  134.         $this->render('index',array(
  135.             'dataProvider'=>$dataProvider,
  136.         ));
  137.     }
  138.  
  139.     /**
  140.      * Manages all models.
  141.      */
  142.     public function actionAdmin()
  143.     {
  144.         $model=new TestEmprendimiento('search');
  145.         $model->unsetAttributes();  // clear any default values
  146.         if(isset($_GET['TestEmprendimiento']))
  147.             $model->attributes=$_GET['TestEmprendimiento'];
  148.  
  149.         $this->render('admin',array(
  150.             'model'=>$model,
  151.         ));
  152.     }
  153.  
  154.     /**
  155.      * Returns the data model based on the primary key given in the GET variable.
  156.      * If the data model is not found, an HTTP exception will be raised.
  157.      * @param integer the ID of the model to be loaded
  158.      */
  159.     public function loadModel($id)
  160.     {
  161.         $model=TestEmprendimiento::model()->findByPk((int)$id);
  162.         if($model===null)
  163.             throw new CHttpException(404,'The requested page does not exist.');
  164.         return $model;
  165.     }
  166.  
  167.     /**
  168.      * Performs the AJAX validation.
  169.      * @param CModel the model to be validated
  170.      */
  171.     protected function performAjaxValidation($model)
  172.     {
  173.         if(isset($_POST['ajax']) && $_POST['ajax']==='test-emprendimiento-form')
  174.         {
  175.             echo CActiveForm::validate($model);
  176.             Yii::app()->end();
  177.         }
  178.     }
  179.  
  180.  
  181.         /*public function beforeSave() {
  182.             if (!parent::beforeSave())
  183.                 return false;
  184.  
  185.             if ($this->isNewRecord)
  186.                     $created_at = time();
  187.             else $updated_at = time();
  188.         }*/
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement