TP PHP自动生成 controller model validate 文件
php吧
全部回复
仅看楼主
level 8
由于项目中使用到的自定义频道,会根据配置自动创建 频道模块的相关文件,有需要的可以借鉴下
public function createFiles($name)
{
$path = root_path();
//controller
$filedir = $path . 'app/admin/controller/';
$model = 'Article' . ucfirst($name);
$table = 'article_' . strtolower($name);
$filename = $model . '.php';
$file = fopen($filedir . $filename, 'w');
$content = "<?php" . PHP_EOL . "namespace app\admin\controller;" . PHP_EOL
. PHP_EOL . "use think\\facade\\Request;" . PHP_EOL
. PHP_EOL . "use app\\common\\facade\MakeBuilder;" . PHP_EOL
. PHP_EOL . "use app\common\builder\FormBuilder;" . PHP_EOL
. PHP_EOL . "use app\common\builder\TableBuilder;" . PHP_EOL
. PHP_EOL . "class {$model} extends Base" . PHP_EOL
. PHP_EOL . "{" . PHP_EOL
. PHP_EOL . "protected \$validate = '{$model}';" . PHP_EOL
. PHP_EOL . "protected \$tableName = '{$table}';" . PHP_EOL
. PHP_EOL . "protected \$modelName = '{$model}';" . PHP_EOL
. PHP_EOL . "}" . PHP_EOL;
fwrite($file, $content);
fclose($file);
}
2024年04月12日 04点04分 1
level 8
谢谢,项目中可以直接使用,希望能帮到你
2024年04月13日 14点04分 3
1