fork download
  1. <?php
  2.  
  3. class ProfileController 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. 'postOnly + delete', // we only allow deletion via POST request
  19. );
  20. }
  21.  
  22. /**
  23. * Specifies the access control rules.
  24. * This method is used by the 'accessControl' filter.
  25. * @return array access control rules
  26. */
  27. public function accessRules()
  28. {
  29. return array(
  30. array('allow', // allow all users to perform 'index' and 'view' actions
  31. 'actions'=>array('index','settings'),
  32. 'users'=>array('@'),
  33. ),
  34. array('deny', // deny all users
  35. 'users'=>array('*'),
  36. ),
  37. );
  38. }
  39.  
  40. /**
  41. * Lists all models.
  42. */
  43. public function actionIndex()
  44. {
  45. $profile = $this->loadModel(Yii::app()->user->id);
  46. $this->render('index',array(
  47. 'model'=>$profile,
  48. ));
  49. }
  50.  
  51. public function actionSettings()
  52. {
  53. $profile = $this->loadModel(Yii::app()->user->id);
  54. $model = new ChangeEmailForm;
  55.  
  56. // if it is ajax validation request
  57. if(isset($_POST['ajax']) && $_POST['ajax']==='change-email-form')
  58. {
  59. echo CActiveForm::validate($model);
  60. Yii::app()->end();
  61. }
  62.  
  63. // collect user input data
  64. if(isset($_POST['ChangeEmailForm']))
  65. {
  66. $model->attributes=$_POST['ChangeEmailForm'];
  67. // validate user input and redirect to the previous page if valid
  68. if($model->validate()) {
  69. $this->redirect('/');
  70. }
  71.  
  72. }
  73.  
  74. $this->render('settings',array(
  75. 'model'=>$model,
  76. 'profile'=>$profile,
  77. ));
  78.  
  79. }
  80.  
  81. /**
  82. * Returns the data model based on the primary key given in the GET variable.
  83. * If the data model is not found, an HTTP exception will be raised.
  84. * @param integer $id the ID of the model to be loaded
  85. * @return User the loaded model
  86. * @throws CHttpException
  87. */
  88. public function loadModel($id)
  89. {
  90. $model=User::model()->findByPk($id);
  91. if($model===null)
  92. throw new CHttpException(404,'The requested page does not exist.');
  93. return $model;
  94. }
  95.  
  96. /**
  97. * Performs the AJAX validation.
  98. * @param User $model the model to be validated
  99. */
  100. protected function performAjaxValidation($model)
  101. {
  102. if(isset($_POST['ajax']) && $_POST['ajax']==='user-form')
  103. {
  104. echo CActiveForm::validate($model);
  105. Yii::app()->end();
  106. }
  107. }
  108. }
  109.  
Runtime error #stdin #stdout #stderr 0.01s 20568KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Fatal error:  Class 'Controller' not found in /home/QGFTVR/prog.php on line 4