Skip to content

TanShun/think-annotation

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 

Repository files navigation

think-annotation for ThinkPHP6

安装

composer require topthink/think-annotation

配置

配置文件位于 config/annotation.php

使用方法

路由注解

<?php

namespace app\controller;

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

/**
 * Class IndexController
 * @package app\controller
 * @Group("bb")
 * @Resource("aa")
 * @Middleware({SessionInit::class})
 */
class IndexController
{

    /**
     * @Inject()
     * @var Cache
     */
    protected $cache;

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

    /**
     * @Route("xx")
     */
    public function xx()
    {
        //...
    }

}

模型注解

<?php

namespace app\model;

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

/**
 * @HasMany("articles", model=Article::class, foreignKey="user_id")
 */
class User extends Model
{

    //...
}

IDE Support

Some IDEs already provide support for annotations:

About

ThinkPHP6注解

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%