CClipWidget.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * CClipWidget 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. * CClipWidget records its content and makes it available elsewhere.
  12. *
  13. * Content rendered between its {@link init()} and {@link run()} calls are saved
  14. * as a clip in the controller. The clip is named after the widget ID.
  15. *
  16. * See {@link CBaseController::beginClip} and {@link CBaseController::endClip}
  17. * for a shortcut usage of CClipWidget.
  18. *
  19. * @author Qiang Xue <qiang.xue@gmail.com>
  20. * @package system.web.widgets
  21. * @since 1.0
  22. */
  23. class CClipWidget extends CWidget
  24. {
  25. /**
  26. * @var boolean whether to render the clip content in place. Defaults to false,
  27. * meaning the captured clip will not be displayed.
  28. */
  29. public $renderClip=false;
  30. /**
  31. * Starts recording a clip.
  32. */
  33. public function init()
  34. {
  35. ob_start();
  36. ob_implicit_flush(false);
  37. }
  38. /**
  39. * Ends recording a clip.
  40. * This method stops output buffering and saves the rendering result as a named clip in the controller.
  41. */
  42. public function run()
  43. {
  44. $clip=ob_get_clean();
  45. if($this->renderClip)
  46. echo $clip;
  47. $this->getController()->getClips()->add($this->getId(),$clip);
  48. }
  49. }