CExtController.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * CExtController class file.
  4. *
  5. * @author Qiang Xue <qiang.xue@gmail.com>
  6. * @link http://www.yiiframework.com/
  7. * @copyright 2008-2013 Yii Software LLC
  8. * @license http://www.yiiframework.com/license/
  9. */
  10. /**
  11. * CExtController is the base class for controllers distributed as extension.
  12. *
  13. * The main purpose of CExtController is to redefine the {@link viewPath} property
  14. * so that it points to the "views" subdirectory under the directory containing
  15. * the controller class file.
  16. *
  17. * @property string $viewPath The directory containing the view files for this controller.
  18. *
  19. * @author Qiang Xue <qiang.xue@gmail.com>
  20. * @package system.web
  21. * @since 1.0
  22. */
  23. class CExtController extends CController
  24. {
  25. private $_viewPath;
  26. /**
  27. * Returns the directory containing view files for this controller.
  28. * This method overrides the parent implementation by specifying the view path
  29. * to be the "views" subdirectory under the directory containing the controller
  30. * class file.
  31. * @return string the directory containing the view files for this controller.
  32. */
  33. public function getViewPath()
  34. {
  35. if($this->_viewPath===null)
  36. {
  37. $class=new ReflectionClass(get_class($this));
  38. $this->_viewPath=dirname($class->getFileName()).DIRECTORY_SEPARATOR.'views';
  39. }
  40. return $this->_viewPath;
  41. }
  42. /**
  43. * @param string $value the directory containing the view files for this controller.
  44. */
  45. public function setViewPath($value)
  46. {
  47. $this->_viewPath=$value;
  48. }
  49. }