Widget应用

    由于widget的基类(Widget Class)是继承了controller的基类(Controller Class)。所以开发Widget文件与开发Controller文件完全相似。所使用的方法也完全相同。注:由于widget是完成页面上一个区域的显示,所以setLayout()在widget开发中不支持。

    获取当前Widget的名称。注:本类方法只能在widget开发文件中使用。参数为空。

    注:关于Widget的其它类方法请参考前面所讲的DoitPHP的Controller的应用中相关的类方法介绍。

    1、Widget的缓存使用

    1. class DemoWidget extends Widget {
    2.  
    3. /**
    4. * Main method
    5. * @access public
    6. * @param array $params 参数
    7. * @return string
    8. */
    9. public function renderContent($params = null) {
    10.  
    11. //Widget的视图缓存文件的调用非同于Controller中的
    12. if($this->cache()) {
    13. return true;
    14. }
    15. ...
    16.  
    17. $this->assign(array(
    18. ...
    19. ));
    20.  
    21. $this->display();
    22. }
    23.  
    24. }