D
D
Dmitry Shcherbakov2018-05-26 11:49:37
symfony
Dmitry Shcherbakov, 2018-05-26 11:49:37

Symfony Routing Component v4 how to import second application yaml file (correct path)?

I have been using https://github.com/klein/klein.php all my life, it is convenient because everything you need to create web applications is already integrated and glued here. But recently it has become rarely updated, issues are growing, pull requests too.
Therefore, I decided to move to the symphony components.
To replace Klein I need:
pimple/pimple - DI
symfony/http-foundation + symfony/http-kernel - Request\Response
symfony/routing + symfony/config + symfony/yaml - symfony routes /
templating - templating
all this is already glued together, and now I have to glue it all myself.
Well, ok, there is a kernel in a separate package, there is an application (several of them all use one kernel and extend it)
Kernel code

$fileLocator = new FileLocator([__DIR__]);
$loader = new YamlFileLoader($fileLocator);
$routes = $loader->load('routes.yaml');

routes.yaml is located in the directory where the kernel is and stores the routes used by the kernel and required by all applications, and you also need to somehow connect the file with individual routes for the application, they are located in the /app/routes.yaml application, I try to connect and it’s clear that the path does not find, how to correctly pass the path to the file?
... несколько маршрутов используемых ядром

# app routes
app_routes:
   resource: '/app/routes.yaml'

UPDATE #1
I found my mistake, indicated the correct path and everything worked, but how can I set this path from the outside, or rather, I found a solution in the docks https://symfony.com/doc/current/routing/service_co...
$container = new ContainerBuilder();
$container->setParameter('app.routes_path', '../../server/app/routes.yaml');

app_routes:
   resource: '%app.routes_path%'

And he told me this Cannot load resource "%app.routes_path%"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
voronkovich, 2018-05-26
@DimNS

The options won't work. The container and the router do not know anything about each other. In Symfony, all the magic is done in the FrameworkBundle: https://github.com/symfony/framework-bundle/blob/8...
Symfony 4 is a microframework, use it instead of building your own:
Also, you can pass in a FileLocator several ways:
See https://api.symfony.com/4.0/Symfony/Component/Conf...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question