上次的入门已经介绍了后台管理插件开发的基本步骤,下面简单写一个示例查询一下用户表
需要已完成以下操作:
1.已创建test后台管理插件 //详见 http://www.cnblogs.com/savokiss/p/3937055.html
1.在test1.inc.php中添加以下代码:
$sql = "SELECT * FROM ".DB::table('common_member')." LIMIT 10"; //定义sql语句,查询common_member表中的前10个用户
$test_result = DB::fetch_all($sql); //查询数据库,将数据存入变量中
这里用到了DB类的两个静态方法,一个是DB::table(),一个是DB::fetch_all(),其他静态方法详见:DB类常用方法
2.修改template文件夹下的test.htm模板
<table class="reg_yest_table">
<tr>
<th>id</th>
<th>用户名</th>
<th>邮箱</th>
</tr>
<!--{loop $test_result $val}-->
<tr>
<td>
$val['uid']
</td>
<td>
$val['username']
</td>
<td>
$val['email']
</td>
</tr>
<!--{/loop}-->
</table>
这里用到discuz模板引擎的loop循环,模板引擎详细语法见:模板标签说明
然后点击插件页面,即可看到查询出来的数据了
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAaIAAABXCAIAAADJQdYmAAAAA3NCSVQICAjb4U/gAAAQBklEQVR4Xu3deVwUdR8H8NkbduUUJE5NkBdpgEimqIGWjz4JaZiS4VWWT5piXhlqmpb2mKJgTyiZiTdCZpoHmpDK45MHZiqKIKSA3NfCcu09z7KgkXEoM84O8Nk/fMnOzvf3/b2/M9+dmR0WDkmSBB4QgAAEOq8At/NODTODAAQgUC+ANoftAAIQ6OQCaHOdvMCYHgQgwG+WICgoqNnn8SQEIAABhgXi4uIojth8m9MFpR6aYmZdZHXdOwqomak1qJlxpncUWg65cNJKb1EQDQIQYJ0A2hzrSoKEIAABegXQ5uj1RDQIQIB1AmhzrCsJEoIABOgVQJuj1xPRIAAB1gmgzbGuJEgIAhCgVwBtjl5PRIMABFgngDbHupIgIQhAgF4BtDl6PRENAhBgnQDaHOtKgoQgAAF6BdDm6PVENAhAgHUCaHOsKwm1hDQV136MvVCqaTkKqZCW1bayvOU1u8gSdUHit3t+l+m/bpZUVZUUPHiUVKn0T2qkK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nL54YFbkp5CBpPzhwUv/KjKeZQxeJzQw1x9QraMT+NZGHPVdMGDpz7dCZDbojXpr2JzMzmRCEMvtoZKR2Uf+PPd9YPOW7yI1zYqqMnIYFf/hPWyPhmIUzSyO/WfhOOd/Gc8z8OT66D1I77v2xLf4BQ/xlL2Z2bvy5KWacdaOwh1qZn7jlix0p3UcFBw7r19vBgivLTbtVbOvjYy9iTKOjDERL1XA011HKjTw7j4DQ7pUPwz2uHYs9FhOxL7uoWisyd+zrG+z5or0It28/jTKjzT0NVcSEQBsCHIG1V+Bcr8A2XobFtAjgIwhaGBEEAhBgrwDaHHtrg8wgAAFaBNDmaGFEEAhAgL0CaHPsrQ0ygwAEaBFAm6OFEUEgAAH2CqDNsbc2yAwCEKBFAG2OFkYEgQAE2CuANsfe2iAzCECAFgG0OVoYEQQCEGCvANoce2uDzCAAAVoE0OZoYUQQCECAvQItfkMJe1NGZhCAQFcSoP5tSS3+6j710F2pEO2fKy3fM9P+4bvSmqDuiNXWVY162jhppW6ICBCAAKsF0OZYXR4kBwEIUBdAm6NuiAgQgACrBdDmWF0eJAcBCFAXQJujbogIEIAAqwXQ5lhdHiQHAQhQF0Cbo26ICBCAAKsF/g8TIgCSa5BBTQAAAABJRU5ErkJggg==" alt="" />
其他数据已略去
注:本文只是示例,正规开发可能会使用discuz缓存机制,有待深入研究