Symfony 2.7: How to change route in code? - symfony

I have a website based on symfony. Routes are declared with yml-files. I use a 3rd-party extention, but wanted to change it's urls. I want to avoid changing the yml-files of this extention because they will be overwritten with the next update. Is there a way to change the route in my php-code instead of the yml-file?

copy the routing file into your application and import it
from symfony doc
Routing is never automatically imported in Symfony.
If you want to include the routes from any bundle, then they must be manually imported from somewhere in your application
(e.g. config/routes.yaml).
The easiest way to "override" a bundle's routing is to never import it at all.
Instead of importing a third-party bundle's routing, simply copy that routing file
into your application, modify it, and import it instead.

Related

Ghost CMS Custom Page assets route

I'm trying to create custom page in Ghost. I named file "news.hbs" for listing all the news items. Also I use webpack. Why while creating new custom page in template all the routes are matching as "news/*"? For example, while webpack generates "news.hbs" file, Ghost requires not an original path "img/header-bg.png", but an "news/img/header-bg.png". How to handle that? In main file "index.hbs" all the paths are valid, without extra folder's names.
You should modify the routes.yaml file for the routes to start working. Look at this documentation for more info: https://ghost.org/docs/api/v3/handlebars-themes/routing/

registering resources with GenericSetup in Plone 5

The page on CSS in the docs http://docs.plone.org/adapt-and-extend/theming/templates_css/css.html#plone-css still suggests using cssregistry.xml, even though the resources are stored in the registry now. Is this the preferred method, as opposed to registry.xml? As far as I can tell it adds them to the plone legacy bundle. Given its name, it sounds like that is something I should be moving away from.
Assuming I don't want to keep using plone legacy bundle, is it bad to add my css/js to the plone bundle or should I create a new bundle for my namespaces?

How do I automatically include routing and config.yml for bundles in /vendors

I've recently started separating out our custom bundles from our Symfony2 app so that they can be shared across multiple projects. I have successfully got them into their own repositories and included back into the main app via Composer. I know I have to register them in AppKernal, but I was hoping that I wouldn't have to link directly to their routing.yml and config.yml files from the ones in the /app/config/*.yml.
Is there a way to automatically include the config files from bundles within the vendors folder?
It turns out a colleague had done this before with config.yml pointed me to this documentation
http://symfony.com/doc/current/cookbook/bundles/extension.html#using-the-load-method
By adding the following to the load() function in your bundle's extension you can have it auto load the various configuration files
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('config.yml');
$loader->load('services.yml');
However this doesn't work with routing.yml because it thinks it has to load an extension matching the name of each route.
Please see my answer - https://stackoverflow.com/a/58140085/1274890
Also as per https://symfony.com/doc/current/bundles/override.html#routing
Routing is never automatically imported in Symfony. If you
want to include the routes from any bundle, then they must be manually
imported from somewhere in your application (e.g. config/routes.yaml).

Symfony2: add routes from my bundle

I created a bundle wjb/ImageBundle but I would like to load its routes without modifying app/config/routing.yml. From FOSRestBundle and few more, I see it is possible but I coudn't figure a way how to do that.
Is there some idiot-proof tutorial? I would like to use annotations but I would accept any other way too.
It's not possible to have routes in your application without registering them.
FOSUserBundle's routes can partly be defined in your security.firewalls configuration.
The others have to be imported as well described in the documentation chapter #6 - FOSUserbundle import routing files.
A workaround may be adding routes when loading a bundle without touching your routing.yml in a CompilerPass.

What is the best place of main assets declared in `base.html.twig`

Each bundle has it's own public directory to store assets (css/js/images).
Now what is the best place for assets used in app\Resources\views\base.htl.twg?
How dose Symfony understand to populate them to public?
usually the assets of templates available in the app/Resources/view directory(like base.html.twig) are placed directly in a subdirectory of the web root like web/includes/css/main.css and called with asset('includes/css/main.css').
If you don't like it, you can easily create your own bundle to store the app assets.
I suggest you to create a DesignBundle to store all base template and assets. This method permit you to share your configuration with other application.

Resources