6257rv7 发表于 2024-10-10 04:08:54

接单必须神器FastAdmin系列二,一键CRUD


    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">FastAdmin <span style="color: black;">供给</span>了一键 CRUD 功能,可<span style="color: black;">经过</span>命令行快速生成 CRUD 代码。CRUD <span style="color: black;">表率</span> Create(创建)、Read(读取)、Update(更新)和 Delete(删除),是一套通用的数据操作功能。一键 CRUD <span style="color: black;">能够</span>快速生成后台<span style="color: black;">掌控</span>器、模型、视图、JS、语言包、菜单、回收站等,<span style="color: black;">极重</span>地<span style="color: black;">加强</span>了<span style="color: black;">研发</span>效率。</p>
    <h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">h2</span>项目结构</h2>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在<span style="color: black;">运用</span>一键 CRUD 功能之前,先<span style="color: black;">熟练</span>一下项目的目录结构。<span style="color: black;">认识</span>项目结构有助于你快速定位和修改生成后的代码。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">FastAdmin项目目录</p>├── application <span style="color: black;">//</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">应用目录</p>│&nbsp;&nbsp; ├── admin <span style="color: black;">//</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">后台管理应用模块</p> ├── controller <span style="color: black;">//</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">掌控</span>器</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">├── lang</p> ├── model <span style="color: black;">//</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">模型</p> ├── validate <span style="color: black;">//</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">验证器</p> ├── view <span style="color: black;">//</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">后台管理视图</p>│&nbsp;&nbsp; ├── api <span style="color: black;">//</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">API应用模块</p>│&nbsp;&nbsp; ├── common <span style="color: black;">//</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">通用应用模块</p>│&nbsp;&nbsp; ├── index <span style="color: black;">//</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">前台应用模块</p>│&nbsp;&nbsp; ├── common.php <span style="color: black;">//</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">通用辅助函数</p>│&nbsp;&nbsp; ├── config.php<span style="color: black;">//</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">基本</span>配置</p>│&nbsp;&nbsp; ├── database.php <span style="color: black;">//</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">数据库配置</p>├── public <span style="color: black;">//</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">框架入口目录</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">│&nbsp;&nbsp; ├── assets</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">│&nbsp;&nbsp; │&nbsp;&nbsp; ├── js</p>│&nbsp;&nbsp; │&nbsp;&nbsp; │&nbsp;&nbsp; ├── backend <span style="color: black;">//</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">后台功能模块JS文件存放目录</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">│&nbsp;&nbsp; │&nbsp;&nbsp; │&nbsp;&nbsp; └── frontend</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">上面的结构<span style="color: black;">保存</span>了关键部分,项目中需要<span style="color: black;">调节</span>的代码大部分集中在这一部分,<span style="color: black;">倘若</span>需要<span style="color: black;">仔细</span><span style="color: black;">认识</span><span style="color: black;">能够</span>到官方文档查看。<span style="color: black;"><span style="color: black;">「</span>https://doc.fastadmin.net/doc/construct.html<span style="color: black;">」</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">application/admin&nbsp;存放后台管理系统的核心代码,<span style="color: black;">包含</span><span style="color: black;">掌控</span>器、模型、视图、语言包、菜单等。一键 CRUD 功能<span style="color: black;">重点</span>生成与此目录<span style="color: black;">关联</span>的代码。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">application/api&nbsp;API 用于<span style="color: black;">研发</span> API 接口,可供 APP、小程序、H5 等<span style="color: black;">外边</span>应用调用。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">application/database.php&nbsp;数据库配置,在上线<span style="color: black;">安排</span>时<span style="color: black;">通常</span>需要修改。</p>
    <h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">h2</span>代码生成</h2>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">FastAdmin <span style="color: black;">供给</span>了一系列命令,让你能够一键生成代码。例如,要生成 fa_blog 表的 CRUD:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">php think crud -t blog</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">要生成 fa_blog 表的 CRUD 并一键生成菜单:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">php think crud -t blog -u 1</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在<span style="color: black;">运用</span> phpStudy 集成环境时,如遇到报错找不到 php 命令。<span style="color: black;">能够</span>将 phpStudy 安装目录下的 Extensions → php → php7.4.3nts 目录添加到系统环境变量。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">有些<span style="color: black;">伴侣</span>可能觉得命令太难记,容易出错。<span style="color: black;">此时</span>,你<span style="color: black;">能够</span><span style="color: black;">运用</span>在线命令插件。登录到系统后台,在插件管理中找到在线命令插件并安装。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/sz_mmbiz_png/bLkJ8qfTjDLMSRiciaa9aphsSphEjBUnPmjoIKzw5AMiah50LSyQuNhYLc3XhFRic0upMf2dIB2eUMYF9XkTP6VhJg/640?wx_fmt=png&amp;from=appmsg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">安装完成后,<span style="color: black;">运用</span>一键生成 CRUD。先<span style="color: black;">选取</span>你<span style="color: black;">自动</span>创建的数据库表,<span style="color: black;">怎样</span>创建后面会讲,<span style="color: black;">而后</span>点击立即执行。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/sz_mmbiz_png/bLkJ8qfTjDLMSRiciaa9aphsSphEjBUnPm4icff2DnffXQgsdQ41SYEzBtF61mjnm41oSJ6bywYfINiaCSUlCrly5g/640?wx_fmt=png&amp;from=appmsg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">第1</span>次执行可能会提示只<span style="color: black;">准许</span>在<span style="color: black;">研发</span>环境下执行命令,这个时候你需要找到application/config.php文件,并将应用调试模式app_debug设置为true。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/sz_mmbiz_png/bLkJ8qfTjDLMSRiciaa9aphsSphEjBUnPmXV7qc0A9ZOoQARhk19R3ibGpXPDj6iajX4IglMZDRFI7Zpq5J8on5ibYg/640?wx_fmt=png&amp;from=appmsg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">执行成功后,将会看到生<span style="color: black;">成为了</span>一系列文件。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/sz_mmbiz_png/bLkJ8qfTjDLMSRiciaa9aphsSphEjBUnPmxH4V3PaBF5rySlIPM92OefLGuGvtfJib1rNWYYknWFb19v7OZdjicuwQ/640?wx_fmt=png&amp;from=appmsg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">另一</span>,还有<span style="color: black;">有些</span>选项可能会用到:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">强制覆盖模式&nbsp;之前<span style="color: black;">已然</span>生成过代码,之后对数据库字段进行<span style="color: black;">调节</span>,重新生成时需要<span style="color: black;">运用</span>强制覆盖模式。<span style="color: black;">倘若</span>你对生成的文件做了改动,会被新生成的文件覆盖,<span style="color: black;">因此呢</span>在<span style="color: black;">运用</span>前请先<span style="color: black;">保留</span>修改过的代码。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">自定义<span style="color: black;">掌控</span>器名&nbsp;<span style="color: black;">通常</span><span style="color: black;">状况</span>下<span style="color: black;">运用</span>默认<span style="color: black;">就可</span>,但<span style="color: black;">倘若</span>需要生成到层级目录中,可<span style="color: black;">运用</span>/分割;</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">删除模式&nbsp;在线命令删除 CRUD 命令会失败,仍然需要<span style="color: black;">运用</span>本地命令模式。</p>
    <h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">h2</span>生成菜单</h2>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">选取</span>上一步生成的<span style="color: black;">掌控</span>器文件,执行命令。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/sz_mmbiz_png/bLkJ8qfTjDLMSRiciaa9aphsSphEjBUnPmHOjk1pezcP44tIZMLcibYyT4baXfTqb2UgPcMA9NI8xGI1kQxhaf46Q/640?wx_fmt=png&amp;from=appmsg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">执行成功后,<span style="color: black;">咱们</span>就能看到左侧多了一个菜单选项。点击进入对应管理模块,<span style="color: black;">能够</span>看到页面<span style="color: black;">包括</span>了内容的增删改查等功能,以及<span style="color: black;">能够</span>看到编辑表单的<span style="color: black;">区别</span>控件类型。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/sz_mmbiz_png/bLkJ8qfTjDLMSRiciaa9aphsSphEjBUnPmnkauTeoWKmymsDGqxX3ClDpYO7NL0OPcoBE9KG6rG7e5XMe9XicH3Kw/640?wx_fmt=png&amp;from=appmsg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">页面生成的内容与数据库字段名<span style="color: black;">叫作</span>、类型、注释等<span style="color: black;">相关</span>。例如表格、表单标题依据注释,表单类型依据字段名<span style="color: black;">叫作</span>,拖拽排序控件依据<span style="color: black;">是不是</span>有权重字段。</p>
    <h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">h2</span>数据库表创建</h2>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在<span style="color: black;">运用</span>一键 CRUD 之前,都需要进行数据库表创建。在 phpStudy 中,你<span style="color: black;">能够</span>安装一个 SQL_Front 数据库管理工具。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/sz_mmbiz_png/bLkJ8qfTjDLMSRiciaa9aphsSphEjBUnPmySZlSGcKoEbodCMQCtxBGtrODsyrzJBkMSNdicx0LPf93v0HWZiaVMLg/640?wx_fmt=png&amp;from=appmsg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">安装完成后登录,就<span style="color: black;">能够</span><span style="color: black;">起始</span>创建你的表了。下面是我刚<span style="color: black;">运用</span>的表字段。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/sz_mmbiz_png/bLkJ8qfTjDLMSRiciaa9aphsSphEjBUnPmp3shcwEAibcUyhnFEQEboicj8rhLWDu4z3lAY7VeHhibibwTOdoq8T8v0w/640?wx_fmt=png&amp;from=appmsg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">详细</span>分析一下:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">表名以 fa_ 开头;</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">SQL_Front 中 id 默认是以大写 I 开头的,统一改成小写;</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">标题title和描述description是 varchar 类型,以普通输入框展示;</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">内容content是个特殊结尾字段,在 FastAdmin 中以 content 结尾的字段,会以富文本编辑器<span style="color: black;">表示</span>,<span style="color: black;"><span style="color: black;">「</span>需安装富文本插件<span style="color: black;">」</span></span>;</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">状态status是特殊字段,是枚举类型,该字段会<span style="color: black;">表示</span> TAB 选项卡;</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">创建时间createtime和更新时间updatetime不需手动<span style="color: black;">守护</span>,不会出<span style="color: black;">此刻</span>新增和编辑表单区域;</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">权重weigh表格排序<span style="color: black;">关联</span>,会<span style="color: black;">表示</span>拖拽排序按钮;</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">标题名<span style="color: black;">叫作</span>和 TAB 选项卡名<span style="color: black;">叫作</span>与注释<span style="color: black;">关联</span>。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">经过</span>以上介绍,相信你<span style="color: black;">已然</span>对<span style="color: black;">怎样</span><span style="color: black;">运用</span>一键 CRUD 功能有了清晰的认识。项目中会有更多<span style="color: black;">区别</span>字段,可参照官方文档。<span style="color: black;"><span style="color: black;">「</span>https://doc.fastadmin.net/doc/database.html<span style="color: black;">」</span></span></p>




nqkk58 发表于 2024-10-19 00:08:49

你的见解独到,让我受益匪浅,期待更多交流。
页: [1]
查看完整版本: 接单必须神器FastAdmin系列二,一键CRUD