PHP code example of yeh110 / think-annotation

1. Go to this page and download the library: Download yeh110/think-annotation 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/ */

    

yeh110 / think-annotation example snippets


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


namespace app\controller;

use yeh110\annotation\Inject;
use yeh110\annotation\route\Get;
use yeh110\annotation\route\Group;
use yeh110\annotation\route\Middleware;
use yeh110\annotation\route\Resource;
use yeh110\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()
    {
        //...
    }


namespace app\model;

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

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

    //...


namespace app\controller;

use yeh110\annotation\auth\Auths;
use yeh110\annotation\auth\Auth;

#[Auths("控制器名称")]
class User
{
    #[Auth('方法一')]
    public function xx()
    {
        //...
    }
    #[Auth('方法二', ['auth'=>false])]
    public function xx()
    {
        //...
    }
    //...