PHP code example of ichynul / builder-man
1. Go to this page and download the library: Download ichynul/builder-man 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/ */
ichynul / builder-man example snippets
namespace app\controller;
use support\Request;
use tpext\builder\common\Builder;
use think\Controller;
use plugin\admin\app\model\Admin;
class Index extends Controller
{
public function index(Request $request)
{
$builder = Builder::getInstance('builder', '测试');
if (request()->method() == 'GET') {
$form = $builder->form();
$form->image('avatar', '头像')->thumbSize(50, 50);
$form->text('username', '账号')->s->success('成功,数据是:' . json_encode($data));
}
}
}
namespace app\admin\controller;
use think\Controller;
use app\common\model\MemberLevel as LevelModel;
use tpext\builder\traits\actions;
class Memberlevel extends Controller
{
//引入控制器动作
use actions\HasBase;//基础,必须
use actions\HasIndex;//列表
use actions\HasAdd;//添加
use actions\HasEdit;//编辑
use actions\HasView;//查看
use actions\HasDelete;//删除
/**
* Undocumented variable
*
* @var LevelModel
*/
protected $dataModel;
protected function initialize()
{
$this->dataModel = new LevelModel;
$this->pageTitle = '代理等级';
$this->sortOrder = 'level asc';
$this->selectSearch = 'name';
}
protected function filterWhere()
{
$searchData = request()->get();
$where = [];
if (!empty($searchData['name'])) {
$where[] = ['name', 'like', '%' . $searchData['name'] . '%'];
}
return $where;
}
/**
* 构建搜索
*
* @return void
*/
protected function buildSearch()
{
$search = $this->search;
$search->text('name', '名称', 3)->maxlength(20);
}
/**
* 构建表格
*
* @return void
*/
protected function buildTable(&$data = [])
{
$table = $this->table;
$table->show('id', 'ID');
$table->text('name', '名称')->autoPost();
$table->text('level', '等级');
$table->show('member_count', '人数统计');
$table->show('description', '描述');
$table->show('create_time', '添加时间');
$table->show('update_time', '更新时间');
$table->getActionbar()
->btnEdit()
->btnView()
->btnDelete();
}
/**
* 构建表单
*
* @param boolean $isEdit
* @param array $data
*/
protected function buildForm($isEdit, &$data = [])
{
$form = $this->form;
$form->text('name', '名称');
$form->number('level', '等级');
$form->textarea('description', '描述');
if ($isEdit) {
$form->show('member_count', '人数统计');
$form->show('create_time', '添加时间');
$form->show('update_time', '更新时间');
}
}
/**
* 保存数据
*
* @param integer $id
* @return void
*/
private function save($id = 0)
{
$data = request()->only([
'name',
'level',
'description',
]);
$result = $this->validate($data, [
'name|名称' => '
'default_lang' => 'zh-cn',
use tpext\builder\common\Module;
use tpext\builder\common\Builder;
//代码可以放在基础控制器的构造函数中、或中间件中
public function setup(){
Module::getInstance()->setUploadUrl('/your/upload/url');//默认为:admin/upload/upfiles
Module::getInstance()->setChooseUrl('/your/choose/url');//默认为:admin/attachment/index
Module::getInstance()->setImportUrl('/your/import/url');//默认为:admin/import/page
//代码逻辑 可参考 tpextbuilder | tpext-tinyvue 中 controller/admin 目录下的以下文件:
// Attachment.php | Import.php | Upload.php
Builder::auth('yourauthclass');//设置权限验证类,需要实现接口:\tpext\builder\inface\Auth。
Builder::aver('1.0.1');//资源版本号,用于控制更新。依赖的UI库可能会更新一些静态资源,修改版本号可以应用最新资源。
}