Home > PHP Framework > ThinkPHP > How to annotate routes in thinkphp

How to annotate routes in thinkphp

藏色散人
Release: 2022-12-20 09:56:27
Original
1093 people have browsed it

Thinkphp method to annotate routing: 1. Open the corresponding tp file; 2. Pass "/* @route('test')*/class Test extends Controller{public function index(){return 'index' ;...}" method to annotate resource routing.

How to annotate routes in thinkphp

#The operating environment of this tutorial: Windows 10 system, thinkphp version 5, Dell G3 computer.

How to annotate routes in thinkphp?

The code is as follows:

/**注解资源路由
 * @route('test')
 */
class Test extends Controller{
    public function index(){//test    get
        return 'index';
    }
    public function create(){//test/create   get
        return 'create';
    }
    public function save(){//test     post
        return 'save';
    }
    public function read(){//test/:id   get
        return 'read';
    }
    public function edit(){//test/:id/edit     get
        return 'edit';
    }
    /** 如果你不想通过资源方式put访问,可以通过注解路由get方式访问
     * @route('update','get')
    */
    public function update(){//test/:id      put   资源路由put方式访问
        return 'update';
    }
    /** 
     * @route('delete','get')
    */
    public function delete(){//test/:id      delete
        return 'delete';
    }
}
Copy after login

Recommended learning: "thinkPHP Video Tutorial"

The above is the detailed content of How to annotate routes in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template