zblogphp怎么在后台取出数据,前台进行调用
zblogphp一些插件的自定义的数据保存在数据库里,由于数据都被序列化了,模板不能够直接调用到,所以需要后台取到,然后传递给模板,才能在模板里取值。
数据内容为:
s:514:"[{"group":"a","title":"\u6211\u7684\u6807\u9898111","img":"http:\/\/www.yoga.cm\/zb_users\/theme\/D_Yoga\/images\/banner01.jpg","url":"http:\/\/www.yoga.cm\/","order":"1"},{"group":"a","title":"\u6211\u7684\u6807\u9898222","img":"http:\/\/www.yoga.cm\/zb_users\/theme\/D_Yoga\/images\/banner02.jpg","url":"http:\/\/www.yoga.cm\/","order":"2"},{"group":"a","title":"\u6211\u7684\u6807\u9898333","img":"http:\/\/www.yoga.cm\/zb_users\/theme\/D_Yoga\/images\/banner03.jpg","url":"http:\/\/www.yoga.cm\/","order":"3"}]";
一、在include.php里面编写处理数据的功能。
function D_Yoga_set(&$template){ global $zbp; $slidesArray = json_decode($zbp->Config('D_Yoga')->SlidesArray,true);//取出数据并反序列化,结果为数组 $template->SetTags('slidesArray', $slidesArray);//把反序列化后的结果$slidesArray赋值给前端模版 }
这是一个幻灯片插件的数据处理功能,功能有了,但并没有被调用。
二、这时候我们需要在include.php页面的上面进行调用。
function ActivePlugin_D_Yoga() { global $zbp; Add_Filter_Plugin('Filter_Plugin_ViewList_Template','D_Yoga_set'); Add_Filter_Plugin('Filter_Plugin_ViewPost_Template','D_Yoga_set'); }
这是两个控制模版页面的接口。
三、在前端模版上调用$slidesArray数据。
{foreach $slidesArray as $slides} <div class="swiper-slide"> <img src="{$slides['img']}" alt="{$slides['title']}"> </div> {/foreach}