定制 topthink/think-annotation 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

topthink/think-annotation

最新稳定版本:v3.0.0

Composer 安装命令:

composer require topthink/think-annotation

包简介

Annotation For ThinkPHP

README 文档

README

安装

composer require topthink/think-annotation

配置

配置文件位于 config/annotation.php

使用方法

路由注解

<?php

namespace app\controller;

use think\annotation\Inject;
use think\annotation\route\Get;
use think\annotation\route\Group;
use think\annotation\route\Middleware;
use think\annotation\route\Resource;
use think\annotation\route\Route;
use think\Cache;
use think\middleware\SessionInit;

#[Group("bb")]
#[Resource("aa")]
#[Middleware([SessionInit::class])]
class IndexController
{

    #[Inject]
    protected Cache $cache;

    public function index()
    {
        //...
    }

    #[Route('GET','xx')]
    public function xx()
    {
        //...
    }
    
    #[Get('cc')]
    public function cc()
    {
        //...
    }
}

默认会扫描controller目录下的所有类
可对个别目录单独配置

//...
    'route'  => [
        'enable'      => true,
        'controllers' => [
            app_path('controller/admin') => [
                'name'       => 'admin/api',
                'middleware' => [],
            ],
            root_path('other/controller')
        ],
    ],
//...

模型注解

<?php

namespace app\model;

use think\Model;
use think\annotation\model\relation\HasMany;

#[HasMany("articles", Article::class, "user_id")]
class User extends Model
{

    //...
}

统计信息

  • 总下载量: 29.63k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 48
  • 点击次数: 1
  • 依赖项目数: 11
  • 推荐数: 0

GitHub 信息

  • Stars: 48
  • Watchers: 2
  • Forks: 25
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2019-06-21