PHP code example of chesterlyd / code-generate-tp-vuetify

1. Go to this page and download the library: Download chesterlyd/code-generate-tp-vuetify library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

chesterlyd / code-generate-tp-vuetify example snippets


protected $modelName  = '模型名';
protected $indexField = ['列表页要显示字段']; 在日常开发中,我们需要在列表中追加表格的列,首先我们需要在这里进行编辑
protected $addField = ['新增页面的表单输入字段'];
protected $editField = ['编辑页面的表单输入字段'];
/**
 * 条件查询,字段名,例如:无关联查询['name','age'],关联查询['name','age',['productId' => 'product.name']],解释:参数名为productId,关联表字段p.name
 * 默认的类型为输入框,如果有下拉框,时间选择等需求可以这样定义['name',['type' => ['type','select']]];目前有select,time_start,time_end三种可被定义
 * 通过模型定义的关联查询,可以这样定义['name',['memberId'=>['member.nickname','relation']]],只能有一个被定义为relation,且字段前的表别名必须为关联的方法名
 * @var array
 */
protected $searchField = [];
protected $pageSize = 10;                 //当前页面显示的数据数量,用于分页
//添加数据验证规则,参考tp5的验证规则
protected $add_rule = [
    'nickName|昵称'  => '

protected $limit = null; //每页显示的数量,为null时取配置文件中的值,可被前端传过来的pageSize参数覆盖
protected $model = ''; //模型名
protected $validate = ''; //位于\app\app\validate下的验证器名,增、删、改操作会调用进行验证,默认与控制器同名
protected $allow = []; //允许的操作,必须为小写,可选值为get\post\put\delete
protected $indexField = [];  //允许在列表页返回的字段名
protected $detailField = []; //允许在详情页返回的字段名
protected $addField   = [];  //增加时允许前端传入的字段名
protected $editField  = [];  //修改时允许前端传入的字段名
protected $with = '';//关联关系
protected $cache = true;//是否开启查询缓存
protected $order = ''; //排序字段

/**
 * 通用返回,程序内部判断应该返回的状态
 * @param $flag
 * @param $failMessage
 * @param array $res
 * @param null|integer $code
 */
public function returnRes($flag, $failMessage, $res = [], $code = null)

/**
 * 操作成功的返回
 * @param array $res
 * @param null|integer $code
 */
public function returnSuccess($res = [], $code = null)

/**
 * 操作失败的返回
 * @param string $failMessage
 * @param null|integer $code
 */
public function returnFail($failMessage = '操作失败', $code = null)
shell
$ php think generate

  indexQuery($sql)      //列表查询的sql语句,如果再列表查询上我们需要其他的操作,可以进行链式操作,如$sql->where(['id' => 1])
  indexAssign($data)    //列表页面输出到视图的数据,如果我们需要往视图中追加数据可以在此方法中实现,如$data['id'] = 1
  pageEach($item, $key) //分页查询后数据遍历处理,方便修改分页后的数据
  

  // 用法与添加页相同
  editAssign($data)
  editData($data)
  editEnd($id,$data)
  

  deleteEnd($id)     数据删除完成后,我们还需要其他操作?那么你可以选择在这个方法里书写你的逻辑,$id是你插入数据库后的id
                     如果开启事务,只需在方法内判断错误即可,如
                     if(!false){//业务逻辑判断
                         $this->returnFail('错误信息') // 输出错误提示
                     }
                     特别注意:无需书写事务提交方法(Db::commit())和成功提示
  

  indexQuery($sql)      //列表查询的模型实例,如果再列表查询上我们需要其他的操作,可以进行链式操作,如$sql->where(['id' => 1]),必须将$sql返回
  indexAssign($data)    //列表页查询到的数据,可以在这个方法里追加或修改数据,必须返回数组
  pageEach($item, $key) //分页查询后数据遍历处理,方便修改分页后的数据
  

  deleteEnd($pk,$data)     数据删除完成后,我们还需要其他操作?那么你可以选择在这个方法里书写你的逻辑,$pk是数据库主键值,复合主键则传入数组,$data是被删除的模型实例
                           if(!false){//业务逻辑判断
                               $this->returnFail('错误信息') // 输出错误提示
                           }
                           特别注意:无需书写事务提交方法(Db::commit())和成功提示