DefaultController.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. class DefaultController extends CController
  3. {
  4. public $layout='/layouts/column1';
  5. public function getPageTitle()
  6. {
  7. if($this->action->id==='index')
  8. return 'Gii: a Web-based code generator for Yii';
  9. else
  10. return 'Gii - '.ucfirst($this->action->id).' Generator';
  11. }
  12. public function actionIndex()
  13. {
  14. $this->render('index');
  15. }
  16. public function actionError()
  17. {
  18. if($error=Yii::app()->errorHandler->error)
  19. {
  20. if(Yii::app()->request->isAjaxRequest)
  21. echo $error['message'];
  22. else
  23. $this->render('error', $error);
  24. }
  25. }
  26. /**
  27. * Displays the login page
  28. */
  29. public function actionLogin()
  30. {
  31. $model=Yii::createComponent('gii.models.LoginForm');
  32. // collect user input data
  33. if(isset($_POST['LoginForm']))
  34. {
  35. $model->attributes=$_POST['LoginForm'];
  36. // validate user input and redirect to the previous page if valid
  37. if($model->validate() && $model->login())
  38. $this->redirect(array('index'));
  39. }
  40. // display the login form
  41. $this->render('login',array('model'=>$model));
  42. }
  43. /**
  44. * Logs out the current user and redirect to homepage.
  45. */
  46. public function actionLogout()
  47. {
  48. Yii::app()->user->logout(false);
  49. $this->redirect(array('index'));
  50. }
  51. }