PHP code example of mycm / easyadmin-sdk

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

    

mycm / easyadmin-sdk example snippets


use EasyAdmin\annotation\ControllerAnnotation;

/**
 * @ControllerAnnotation(title="商品管理", auth=true)
 */
class GoodsController
{
    // ...
}

use EasyAdmin\annotation\NodeAnnotation;

/**
 * @NodeAnnotation(title="商品列表")
 */
public function index()
{
    // ...
}

use EasyAdmin\auth\Node;

$node = new Node(
    $baseDir,              // 控制器所在目录
    $annotationCacheDir,   // 注解缓存目录
    'app\admin\controller' // 命名空间前缀
);

$nodeList = $node->getNodelist();

[
    ['node' => 'goods',         'title' => '商品管理', 'is_auth' => true,  'type' => 1], // 控制器节点
    ['node' => 'goods/index',   'title' => '商品列表', 'is_auth' => true,  'type' => 2], // 方法节点
    ['node' => 'goods/add',     'title' => '添加商品', 'is_auth' => false, 'type' => 2],
]

use EasyAdmin\console\CliEcho;

CliEcho::success('操作成功');
CliEcho::error('操作失败');
CliEcho::warn('警告信息');
CliEcho::notice('提示信息');

// 自定义颜色
echo CliEcho::initColoredString('自定义文字', 'green', 'light_gray');

use EasyAdmin\tool\CommonTool;

// 下划线转驼峰
CommonTool::lineToHump('user_name');       // 'UserName'

// 驼峰转下划线
CommonTool::humpToLine('UserName');        // 'user_name'

// 获取真实客户端 IP
$ip = CommonTool::getRealIp();

// 递归读取目录下所有文件
$files = CommonTool::readDirAllFiles('/path/to/dir');

// 模板变量替换
$result = CommonTool::replaceTemplate('Hello {{name}}', ['name' => 'World']);
// 'Hello World'

use EasyAdmin\upload\Uploadfile;

$upload = Uploadfile::instance()
    ->setUploadType('local')              // local / alioss / qnoss / txcos
    ->setUploadConfig($uploadConfig)
    ->setFile($file)
    ->setTableName('system_uploadfile')
    ->save();

$uploadConfig = [
    // 通用
    'upload_type'           => 'local',
    'upload_full_path'      => false,
    'upload_custom_domain'  => '',

    // 缩略图
    'image_thumb'           => false,
    'image_thumb_width'     => 500,
    'image_thumb_height'    => 500,

    // 水印
    'add_watermark'         => false,
    'watermark_type'        => 'text',     // text / image
    'watermark_text'        => 'My Watermark',
    'watermark_text_size'   => 50,
    'watermark_image'       => '/path/to/watermark.png',

    // 阿里云 OSS
    'alioss_access_key_id'  => '',
    'alioss_access_key_secret' => '',
    'alioss_endpoint'       => '',
    'alioss_bucket'         => '',
    'alioss_domain'         => '',

    // 七牛云
    'qnoss_access_key'      => '',
    'qnoss_secret_key'      => '',
    'qnoss_bucket'          => '',
    'qnoss_domain'          => '',

    // 腾讯云 COS
    'txcos_secret_id'       => '',
    'txcos_secret_key'      => '',
    'txcos_region'          => '',
    'txcos_bucket'          => '',
];

use EasyAdmin\upload\interfaces\OssDriver;

class MyDriver implements OssDriver
{
    public function save($objectName, $filePath)
    {
        // 实现上传逻辑
        return [
            'save' => true,
            'msg'  => '上传成功',
            'url'  => 'https://...',
        ];
    }
}