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>

结果

相关推荐
Slow菜鸟3 小时前
AI学习篇(五) | awesome-design-md 使用说明
人工智能·学习
ZC跨境爬虫3 小时前
跟着 MDN 学 HTML day_9:(信件语义标记)
前端·css·笔记·ui·html
前端老石人3 小时前
HTML 字符引用完全指南
开发语言·前端·html
REDcker3 小时前
Linux信号机制详解 POSIX语义与内核要点 sigaction与备用栈实践
linux·运维·php
幼儿园技术家3 小时前
前端如何设计权限系统(RBAC / ABAC)?
前端
狐狐生风3 小时前
LangChain 向量存储:Chroma、FAISS
人工智能·python·学习·langchain·faiss·agentai
狐狐生风4 小时前
LangChain RAG 基础
人工智能·python·学习·langchain·rag·agentai
前端摸鱼匠5 小时前
Vue 3 的v-bind合并行为:讲解v-bind与普通属性合并的规则
前端·javascript·vue.js·前端框架·ecmascript
REDcker5 小时前
浏览器端Web程序性能分析与优化实战 DevTools指标与工程清单
开发语言·前端·javascript·vue·ecmascript·php·js
努力努力再努力FFF6 小时前
医生对AI辅助诊断感兴趣,作为临床人员该怎么了解和学习?
人工智能·学习