Home  >  Article  >  Backend Development  >  关于thinkphp中的widget的开发

关于thinkphp中的widget的开发

WBOY
WBOYOriginal
2016-06-23 14:00:17904browse

class HotkeyWidget extends Widget {
        public function render($data) {
$node=M('Hotkey');//这里是数据库表的实例化
$data=$node->limit('0,10')->select();
$data['list']=$data; 
$content = $this->renderFile ( ADDON_PATH . '/widgets/Hotkey.html', $data);
return $content;
}



我在Hotket.html中应该怎么调用HotkeyWidget 类中读取出来的数据?  如果应用到模版上面应该怎么调用?


回复讨论(解决方案)

会用thinkphp的,难道就不会用自定义的?

同求解答~~~楼上的就没决绝问题啊。

我也遇到同?的??...  

1.widget一般放在Lib目录下,比如排行榜的Widget,建立文件TopLankWidget.class.php和TopLank.html
2.在php页面写关于排行榜的方法,在页面中调用{:W(‘TopLank’,array(‘type’=>’auto’,'title’=>’排行榜’))}

调用读取出来的数据:

    

  • {$L['goods_id']}

  •     
  • {$L['category']}

  •    
  • {$L['sort']}

  •    
  • {$L['store_id']}

  •      
  • {$L['goods_name']}

  •     
  • {$L['price']}

  •     
  • {$L['desc']}

  •       
  • {$L['img']}

  •  

    模版调用
    {:W('Hotkey')}

    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn