1. Go to this page and download the library: Download wansh/thinkeasyadmin 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/ */
wansh / thinkeasyadmin example snippets
#project\app\admin\controller\Category.php
namespace app\admin\controller;
use easyadmin\app\columns\lists\ListDateTime;
use easyadmin\app\columns\lists\ListImage;
use easyadmin\app\columns\lists\ListText;
use easyadmin\app\libs\ListField;
class Category extends \easyadmin\controller\Admin
{
protected $pageName = '分类';
protected function configListField(ListField $list)
{
$list
->addField('id', 'ID', ListText::class)
->addField('name', '分类名称', ListText::class)
->addField('icon', '图标', ListImage::class)
->addField('time', '创建时间', ListDateTime::class);
}
}
#project\app\admin\controller\Category.php
namespace app\admin\controller;
use easyadmin\app\libs\PageForm;
use easyadmin\app\columns\form\FormSelect;
use easyadmin\app\columns\form\FormSwitch;
use easyadmin\app\columns\form\FormText;
use easyadmin\app\columns\form\FormTextarea;
use easyadmin\app\columns\form\FormUpload;
class Category extends \easyadmin\controller\Admin
{
/**
* 配置表单
* @param PageForm $page
*/
protected function configFormField(PageForm $page)
{
$page
->addField('parent_id', '上级分类', FormSelect::class, [
'table' => 'category',
'pk' => 'id',//使用查询,的主键
'property' => 'name',//查询显示字段
])
->addField('name', '分类名称', FormText::class)
->addField('icon', '分类图标', FormUpload::class)
->addField('intro', '分类简介', FormTextarea::class)
->addField('is_del', '是否删除', FormSwitch::class);
if ($this->formType == 'edit') {
//编辑页面特有的字段
$page->addField('edit_field', '名称', FormText::class);
}else{
//添加页面特有的字段
$page->addField('add_field', '名称', FormText::class);
}
}
}