FastAdmin使用建议

1.规划好数据表 !!!
直接用命令创建后台管理菜单

//生成fa_test表的CRUD
php think crud -t test
//生成fa_test表的CRUD且一键生成菜单
php think crud -t test -u 1
//删除fa_test表生成的CRUD
php think crud -t test -d 1
//生成fa_test表的CRUD且控制器生成在二级目录下
php think crud -t test -c mydir/test
//生成fa_test_log表的CRUD且生成对应的控制器为testlog
php think crud -t test_log -c testlog
//生成fa_test表的CRUD且对应的模型名为testmodel
php think crud -t test -m testmodel
//生成fa_test表的CRUD且生成关联模型category,外链为category_id,关联表主键为id
php think crud -t test -r category -k category_id -p id
//生成fa_test表的CRUD且所有以list或data结尾的字段都生成复选框
php think crud -t test --setcheckboxsuffix=list --setcheckboxsuffix=data
//生成fa_test表的CRUD且所有以image和img结尾的字段都生成图片上传组件
php think crud -t test --imagefield=image --setcheckboxsuffix=img
//关联多个表,参数传递时请按顺序依次传递,支持以下几个参数relation/relationmodel/relationforeignkey/relationprimarykey/relationfields/relationmode
php think crud -t test --relation=category --relation=admin --relationforeignkey=category_id --relationforeignkey=admin_id

说明 :1. 如果配置了数据表前缀 ,则不用指定前缀
2. 如果数据表为 fa_test_log ,在创建的时候需要指定名字,否则为创建在 test / log.php ,处于test 目录下。指定名字 -c testlog
3. 通过命令行生成的文件有 (例如 php think crud -t share_img -c share/img)

application/admin/controller/share/Img.php
application/admin/mode/share/Img.php
application/admin/validate/share/Img.php
application/admin/view/share/Img/add.html
application/admin/view/share/Img/edit.html
application/admin/view/share/Img/index.html
public/assets/js/backend/share/img.js       
创建的目录不存在会自动创建

说一下模型关联。在开始做的时候crud没有添加关联,但是使用的时候部分数据又是需要关联的,这时候我们可以自己来修改。首先要在控制器中 加上 protected $relationSearch = true;
复制下父类的index()方法,在模型查询的时候加入 with方法

public function index(){
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage,则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $total = $this->model
                ->with(['user','prizes']) 
                ->where($where)
                ->order($sort, $order)
                ->count();

            $list = $this->model
                ->with(['user','prizes'])
                ->where($where)
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();
            $list = collection($list)->toArray();
            $result = array("total" => $total, "rows" => $list);

            return json($result);
        }
        return $this->view->fetch();
    }

然后修改模型类

//模型关联
    public function user()
    {
        return $this->belongsTo('app\admin\model\User','user_id','id', [], 'LEFT')->setEagerlyType(0);
    }
    public function prizes()
    {
        return $this->belongsTo('app\admin\model\Prizes','prizes_id','id', 'prizes', 'LEFT')->setEagerlyType(0);
    }

上面的with关联的两个数据模型,分别对应模型类的两个方法.
$this->belongsTo(‘app\admin\model\Prizes’,‘prizes_id’,‘id’, ‘prizes’, ‘LEFT’)->setEagerlyType(0);
参数分别表示 模型名,关联外键,关联主键,别名(已废弃),join类型
最后在js文件下,修改 参数名就ok了
{field: 'user.username', title: __('User_id')},
field 参数表示需要输出的值,这里表示关联的user表的username字段,__(‘User_id’)表示的多语言,配置在application/admin/lang/zh-cn/share/img.php

生成完目录后需要生成菜单,目录还是比较简单

//一键生成share控制器的权限菜单
php think menu -c share
//一键生成share/img控制器的权限菜单
php think menu -c share/img
//删除share/img控制器生成的菜单
php think menu -c share/img -d 1
//一键全部重新所有控制器的权限菜单
php think menu -c all-controller	 		

官方文档地址(https://doc.fastadmin.net/docs/index.html)

<think>好的,用户现在想了解如何使用小皮工具(可能是指phpstudy)来运行FastAdmin框架。首先,我需要回忆一下小皮工具通常指的是什么。小皮面板,也就是phpstudy,是一个集成了Apache/Nginx、PHP、MySQL等环境的工具,方便用户在Windows或Linux上快速搭建PHP开发环境。 接下来,用户需要具体的步骤来配置FastAdmin。首先,确保他们已经下载并安装了phpstudy。然后,可能需要创建一个新的网站,配置域名和根目录。FastAdmin作为ThinkPHP的应用,可能需要伪静态配置,所以需要检查Apache或Nginx的rewrite规则是否正确设置。 另外,用户可能需要安装Composer来管理依赖,虽然FastAdmin可能已经自带vendor,但最好确认一下是否需要执行composer install。数据库的创建和配置也是关键步骤,用户需要导入FastAdmin的SQL文件,并修改对应的数据库配置文件,比如application/database.php。 还需要考虑PHP的版本是否符合FastAdmin的要求,比如PHP7.1以上。用户可能会遇到常见问题,比如权限问题、伪静态未开启导致的路由错误,或者PHP扩展未安装(如fileinfo、openssl等)。此外,如果是在本地开发,hosts文件的配置是否正确,域名解析是否指向本地服务器。 参考之前提供的引用,比如引用[4]提到FastAdmin的配置类型,可能需要指导用户如何在系统配置中进行相关设置。同时,引用[3]中提到的插件兼容性问题,可能需要提醒用户注意插件版本,尤其是在特定环境下运行时的问题。 最后,整理一个清晰的步骤列表,涵盖环境准备、FastAdmin部署、数据库配置、伪静态设置、访问安装向导等环节,并附上常见问题解决方法,确保用户能够顺利运行FastAdmin。同时,生成相关问题,帮助用户进一步解决可能遇到的扩展配置或开发问题。</think>### 使用小皮工具(phpstudy)运行FastAdmin的配置方法 #### 一、环境准备 1. **安装phpstudy** - 下载最新版小皮面板(phpstudy)并完成安装 - 启动Apache/Nginx + MySQL + PHP环境组合(建议PHP7.1+) 2. **检查必要组件** ```bash PHP扩展需开启:fileinfo、openssl、mbstring、gd、pdo_mysql ``` #### 二、FastAdmin部署 1. **项目下载与解压** - 从官网下载FastAdmin完整版 - 解压到phpstudy网站根目录(如:`phpstudy_pro/WWW/fastadmin`) 2. **创建虚拟主机** ```nginx # Nginx伪静态配置示例 location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php?s=$1 last; break; } } ``` Apache用户需开启`mod_rewrite`模块 3. **数据库配置** - 通过phpstudy创建MySQL数据库(字符集utf8mb4) - 修改配置文件:`application/database.php` ```php return [ 'hostname' => '127.0.0.1', 'database' => 'fastadmin', 'username' => 'root', 'password' => 'root' // phpstudy默认密码 ]; ``` #### 三、初始化安装 1. 访问 `http://localhost/fastadmin/public/install.php` 2. 根据向导完成数据库安装 3. 安装完成后删除`public/install.php`文件 #### 四、常见问题解决 1. **路由404错误** - 检查伪静态配置是否正确[^4] - 确认`.htaccess`文件存在(Apache) ```apache <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^(.*)$ public/$1 [L] </IfModule> ``` 2. **PHP扩展缺失** - 在phpstudy管理界面启用`fileinfo`等必要扩展[^3] 3. **权限问题** ```bash chmod -R 755 runtime chmod -R 755 public/uploads ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值