PHP code example of ahaschool / aha-php

1. Go to this page and download the library: Download ahaschool/aha-php 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/ */

    

ahaschool / aha-php example snippets


/**
 * 代码示例
 *
 * @tag name 中文名称
 */
class XxxController {
    /**
     * api接口1
     * 
     * @api get /api/get
     * @return array \Xxx\Xxx
     */
    public function getXxx(Request $request)
    {
        // todo...
    }

    /**
     * api接口2
     * 
     * @api post /api/create
     * @see in {"name":"name","type":"string","desc":""}
     * @see in {"name":"head","type":"object","desc":""}
     * @see in {"name":"head.avatar","type":"string","desc":""}
     * @see out {"name":"status","type":"integer","desc":""}
     */
    public function postXxx(Request $request)
    {
        // todo...
    }
}

class Xxx
{
    // 筛选
    public static $args = [
        'name regexp keyword|desc:关键字查询',
        'status',
    ];
    // 入参
    public static $rule = [
        'id' => 'int',
        'name' => 'string',
        'status' => 'int',
        'xxx.*.id' => 'int',
        'xxx.*.value' => 'string',
    ];
    // 定义
    public static $type = [
        'id' => 'int|desc:主键id',
        'name' => 'string|desc:名称',
        'status' => 'integer|desc:状态',
        'xxx' => 'array|relation:xxx|desc:xxx关系',
    ];
}

/**
 * api接口x
 * 
 * @api post /xxx/xxx/get,create,update,status,updown
 * @see note-get x详情,只用传id
 * @see note-create x创建,不可传id
 * @see note-update x更新,传id和数据
 * @see note-status x状态,id和status
 * @see note-updown x排序,id和sort上下移
 * @source input \Xxxx\Xxx::$xxx
 * @source param {}
 * @return array \Xxx\Xxx
 * @return object {"status":{"type":"integer"}}
 */