Open nCrazed opened 5 years ago
Also ran into that issue today on a new project. Is there any way to help without knowing java?
+1
+1
+1
+1
+1
there is a temp workaround?
+1
With release 0.19.190 you can add the var/cache/dev/UrlGenerator.php
in Settings
> Languagues & Frameworks
> PHP
> Symfony
> Routing
which solves the problem.
Thank you very much @Haehnchen
Yes, from 0.19.190
version, it works!
With Symfony 5, UrlGenerator.php no longer exists (I think Nicolas Grekas made a HUGE optimization with the routing). Now there are url_generating_routes.php and url_matching_routes.php
yes the new format was added via: https://github.com/Haehnchen/idea-php-symfony2-plugin/commit/71b03398eee1906f7737aea2e4d03eaec45b1c6f thats why the routes are working now and also autodetection of this was was improved.
so UrlGenerator
or url_generating_routes
can be taken if its not used by its own.
for me it still can be approved to also load config eg via config/routes.yaml
to not relay on this routing file, but i guess most common usages would now work.
It works so well! Thank you guys :D
I'm still manually having to add the url_generating_routes.php
file to the PHP > Symfony > Routes settings in order for the name_prefix
setting to be picked up.
Previous comments in this issue seem to suggest that I shouldn't have to. Have I done something wrong? I'm using 0.23.212
in 2021.1
I have a similar problem but I also use hostname filtering:
controllers:
resource:
path: ../../src/Controller/yyy
namespace: xxx\Controller\yyy
type: attribute
name_prefix: yyy_
host:
- app.site.com
- staging.site.com
- staging.localhost
- test.local
- staging.server2.com
This means that if I have a controller route called abcd
then the url_generating_routes.php
file contains yyy_abcd.0
, yyy_abcd.1
, yyy_abcd.2
, yyy_abcd.3
, yyy_abcd.4
because of the hosts.
However, in PHPStorm, I can definitely use redirectToRoute('yyy_abcd', [ ... ])
and it works (Symfony will pick the route that matches the host currently being used).
So the workaround to add the URLs into the plugin configuration works for the prefix part, but not the suffix.
I read the code a bit, in the url_generating_routes.php
the array contains the controller information which seems to be parsed here: https://github.com/Haehnchen/idea-php-symfony2-plugin/blob/master/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/Route.java#L40
I guess that if you add a test for index _canonical_route
you will be able to parse the real (canonical) route name.
For example (with the code snippet in my previous comment), the url_generating_routes.php
would contain these entries for #[Route(..., name="abcd")
:
return [
...
// this is for the 1st hostnam, app.site.com
'yyy_abcd.0' => [
['var1'],
[
'_controller' => 'xxx\Controller\yyy:abcd',
'_locale' => 1,
'_canonical_route' => 'yyy_abcd'
],
[['variable', '/', 'xxx', 'var1', true], ['text', '/path']],
[['text', 'app.site.com']]],
[],
[]
],
// 2nd hostname, staging.site.com
'yyy_abcd.1' => [
['var1'],
[
'_controller' => 'xxx\Controller\yyy:abcd',
'_locale' => 1,
'_canonical_route' => 'yyy_abcd'
],
[['variable', '/', 'xxx', 'var1', true], ['text', '/path']],
[['text', 'staging.site.com']]],
[],
[]
],
// and so on
...
];
This is a bit messed up compared to what is actually there, but you get the idea. I suppose it's easy to reconstruct such a file just by adding 2 hosts in the YML conf.
I suppose the UI could allow routes with the canonical name (e.g. yyy_abcd
) as well as the full name with a specific host name (e.g. yyy_abcd.0
though I wouldn't use it myself).
See: https://symfony.com/blog/new-in-symfony-4-1-prefix-imported-route-names
Example
The following configuration defines a single route named
admin.dashboard
. Referencing the route name triggers "Route Missing" inspections as the plugin thinks that the route name isdashboard
.