Widget应用
由于widget的基类(Widget Class)是继承了controller的基类(Controller Class)。所以开发Widget文件与开发Controller文件完全相似。所使用的方法也完全相同。注:由于widget是完成页面上一个区域的显示,所以setLayout()在widget开发中不支持。
获取当前Widget的名称。注:本类方法只能在widget开发文件中使用。参数为空。
注:关于Widget的其它类方法请参考前面所讲的DoitPHP的Controller的应用中相关的类方法介绍。
1、Widget的缓存使用
- class DemoWidget extends Widget {
- /**
- * Main method
- * @access public
- * @param array $params 参数
- * @return string
- */
- public function renderContent($params = null) {
- //Widget的视图缓存文件的调用非同于Controller中的
- if($this->cache()) {
- return true;
- }
- ...
- $this->assign(array(
- ...
- ));
- $this->display();
- }
- }