PHP code example of koalaphp / code-generator
1. Go to this page and download the library: Download koalaphp/code-generator 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/ */
koalaphp / code-generator example snippets
class CustomDaoTpl
{
public static $template = <<<EOT
namespace Library\Dao\%dbNamespace%;
use Koala\Database\SimpleDao;
/**
* Created by Koala Command Tool. Custom Dao Tpl
* Author: %author%
* Date: %date%
*
* @method %tableModelName% findOne(\$conditions = [], \$sort = "id desc")
* @method %tableModelName%[] findAllRecordCore(\$conditions = [], \$sort = "id desc", \$offset = 0, \$limit = 20, \$fieldList = [])
* @method \\Generator|%tableModelName%[]|%tableModelName%[][] createGenerator(\$conditions = [], \$numPerTime = 100, \$isBatch = false)
*
* %tableComment% Dao 类,提供基本的增删改查功能
*/
class %tableDaoName% extends SimpleDao
{
// 连接的数据库
protected \$database = '%dbName%';
// 表名
protected \$table = '%tableName%';
// 主键字段名
protected \$primaryKey = '%primaryKey%';
// select查询的时候是否使用master,默认select也是查询master
protected \$isMaster = true;
// select查询出来的结果映射的Model类
protected \$modelClass = %tableModelName%::class;
%fieldList%
}
EOT;
}
class CustomModelTpl
{
public static $template = <<<EOT
namespace Library\Dao\%dbNamespace%;
/**
* Created by Koala Command Tool. Custom Model Tpl
* Author: %author%
* Date: %date%
*
* %tableComment% Model 模型类
*/
class %tableModelName%
{
%fieldList%
}
EOT;
}