简体   繁体   中英

How to add a prefix to many routes in Symfony 4

I'd like all my Controller action routes in the namespace 'App\\Controller\\Api' to have the prefix '/api'. I also want to use annotations inside the controllers to set the rest of the route.

In Symfony 3 this was done by editing 'config/routing.yml':

app:
    resource: '@AppBundle/Controller/Api'
    type: annotation
    prefix: /api

How can I do this in Symfony 4? Do I need to make a bundle? Which config file would I use since I don't have a 'config/routing.yml'?

Ok It looks like I should have just tried real path names. The following worked in 'config/routes.yaml':

api:
    prefix: /api
    resource: '../src/Controller/Api'

At first run composer require annotations and then

use Symfony\Component\Routing\Annotation\Route;

/**
* @Route("/blog")
*/
class BlogController extends Controller
{

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM