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