PHP code example of rrbrr / cgf

1. Go to this page and download the library: Download rrbrr/cgf 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/ */

    

rrbrr / cgf example snippets



namespace app\controller;
use Cgf\Framework\Thinkphp\BaseController;

class Error extends BaseController
{
    public function __call($method, $args)
    {
        return 'error request!';
    }
}

   
      'options'=>[
          0=>'禁用'
          1=>'正常',
          2=>'审核中'
        ]
      
      'options'=>[
          'function'=>"get_allf_lag('a','###','@@@')"
        ]

return array(
    'base' =>
        array(
            'username'    =>
                array(
                    'name' => 'uesrname',
                    'type' => 'text',
                    'size' => 10,
                    'zh'   => 'id',
                ),
            'status_flag' =>
                array(
                    'name'      => 'status_flag', //数据表字段名
                    'type'      => 'text',        //类型
                    'size'      => 10,
                    'rawOption' => '0:禁用,1:正常', //可选值
                    'options'   =>
                        array(
                            0 => '禁用',
                            1 => '正常',
                        ),
                    'zh'        => '用户状态',            //后台列表中展示的标题
                    'show_text' => 'status_flag_text',  //将枚举的数学类型的值转为文本显示
                ),
        )
);

//cgf格式
`course_title` varchar(255) NOT NULL DEFAULT '' COMMENT '产品名称|1011||show_func=order_course_title',

//php
function order_course_title($title,$key,$v){ // 调用代码:call_user_func_array(函数名,[字段值,字段名,此行记录所有数据]);
    
    $title = $v['course_title'];
    $url = "http://www.21mmm.com/course/{$v['course_id']}";
    $url = "<a href='{$url}' target='_blank' title='{$title}'>$title</a>";
    return $url;
}

//cgf格式
`course_title` varchar(255) NOT NULL DEFAULT '' COMMENT '产品名称|1011||show_func=order_course_title-course_id',

//php
function order_course_title($title,$key,$course_id){
    
    $title = $v['course_title'];
    $url = "http://www.21mmm.com/course/{$v['course_id']}";
    $url = "<a href='{$url}' target='_blank' title='{$title}'>$title</a>";
    return $url;
}

// cgf格式
  `category_id` int(11) unsigned NOT NULL COMMENT '分类id-select|1111|title')->select();
    return $r;  //从分类表,取出分类id,分类title

  }

  //这样category_id 显示的select就会是这样的 <option value="分类id1">分类tilte1</option>
 php 
$cgfConf                       = []; //
$cgfConf['dbConfig']           = ['host'=>'localhost','dbname'=>'test','username'=>'root','password'=>'123456','type'=>'mysql']; //数据库连接配置
$cgfConf['savePath']           = $appBasePath . "/Cgf/definition"; //保存cgf生成的定义文件
$cgfConf['framework']          = 'thinkphp'; //使用的框架
$cgfConf['validate']           = 'thinkphp'; //使用验证
$cgfConf['form']               = 'bootstrap'; //表单使用的框架
$cgfConf['currentName']        = 'common'; //当前模块名
$cgfConf['tableName']          = $tableName; //表名
$cgfConf['controllerName']     = $this->controllerName; //控制器名
$cgfConf['appRootPath']        = $appBasePath; //框架应用程序根目录
$cgfConf['parentTemplatePath'] = $appBasePath . '/view/public/'; //cgf生成模板使用的父模板,cgf会根据这里的模板来生成应用模板
$cgfConf['templateSavePath']   = $appBasePath . "/view/{$tableName}"; //cgf生成的模板保存路径
$cgfConf['availableModule']    = ['common', 'admin']; //可用模块
$cgfConf['autoHiddenPrimaryKey']    = true; //是否将主键表单类型设为hidden