fastadmin学习08-查询数据渲染到前端

index.php查询,这个是前台的index.php

php 复制代码
public function index()
{
    $slideImgs = Db::name("slideimg")
        ->where("status",'=','normal')
        ->limit(5)
        ->order('sort','desc')->select();
    $productList = Db::name("product")
        ->where("deletetime",'exp','is null')
        ->limit(10)
        ->order('updatetime','desc')->select();
    $this->view->assign('slideImgs',$slideImgs);
    $this->view->assign('productList',$productList);
    $this->view->assign('title', __('首页'));
    //设置页面名称,方便根据页面名称加载不同的js和css
    $this->view->assign('pageName','index' );
    return $this->view->fetch();
}

模板代码

html 复制代码
<div>
    <!--{php}print_r($slideImgs);{/php}-->
    <!--{php}print_r($productList);{/php}-->
    {foreach $slideImgs as $key=>$img }
    <img src="{$img.image}"/>
    {/foreach}
    {foreach $productList as $key=>$product }
    <img src="{$product.product_image}"/>
    <div>{$product.name}</div>
    <div>{$product.marketPrice}</div>
    {/foreach}
</div>

结果

相关推荐
fanfan_hongyun5 分钟前
UE5.1 学习记录-玩家控制器
学习·ue5
晴天161 小时前
前端 postMessage 使用场景
前端·javascript·网络
zhanghaha13142 小时前
HTML系列教程:15_标签 全称 + 简写 超详细讲解(新手专用)
前端·html
zhanghaha13142 小时前
HTML系列教程:14_HTML 表单与输入框 <form>、<input> 零基础详解
java·前端·javascript
IMPYLH2 小时前
HTML 的 <samp> 元素
前端·网络·html
IMPYLH2 小时前
HTML 的 <script> 元素
前端·html
weixin_493503677 小时前
Vue3 前端生成 PDF:会员证书与活动签到表的三种打印方案与踩坑记录
前端·pdf·状态模式
传奇开心果编程7 小时前
【xilem0.4基础语法学与练】第13课:Xilem 0.4 最简短代码体现“一切皆设计图“
学习·rust·前端框架
小雪崩8 小时前
嵌入式学习 day45:51单片机基础
学习·51单片机
尾善爱看海10 小时前
前端算法与手写题集
前端·算法