Enhancement / Suggestion : Configurable Extra Patterns in main.php?


(James Crittenden Main) #1

Hey guys,

I’m currently working on a REST API, I have been trying to create a route that would accomplish the following:

Objective :

- Forego the need for the ?expand=etc if I know in advance I'll want to utilize extraFields() on certain custom actions within my controller. 

Proposal : Configurable ‘extraPatterns’ within Url Rules.




'class'      => 'yii\rest\UrlRule',

'controller' => 'v1/posts',

'tokens'     => [

    '{id}' => '<id:\\w+>'

],

'extraPatterns' => [

     'GET full-post/{id}' => [

           'action' => 'fullPost'

           'expand' => ['authors', 'comments'] <----- This is what I am proposing

      ]

 ]




Result : Ability to request posts/full-post/<id> and it return the relational data without the need to

?expand=authors,comments.


(Alexander Makarov) #2