Extending parent routing when extending bundles - symfony

In Symfony2 (2.0.3) I have a BetaBundle that is set as the parent of a AlphaBundle. Is it possible to override some routes while still keeping the parent originals routing definition ?
I have tried importing the parent routing.yml inside the child routing.yml file but it naturally result in a circular reference exception.
Is there any standard way to achieve this using yml and files named routing.yml in the same relative path ?

When you override your AlphaBundle anything that uses the #AlphaBundle shortcut will look in #BetaBundle first. The only way I've found to solve this kind of problem is to have the extending bundle (BetaBundle) quit using the # shortcut, and include your AlphaBundle's route using it's path.
As an alternative you could try renaming your BetaBundle's route file so that it doesn't override AlphaBundle's file, and then configure your app/config/routing.yml to include your BetaBundle's renamed routing file.

Related

Symfony include static html in template

I just started to learn how to use Symfony which i believe is straight forward but i have a little problem with the templating engine. I want to include a static HTML fragment in one of my twig templates in Symfony (2.5.6). For now i created a static subfolder inside the resources directory (this might change but it definitely won't be inside the view folder). However i can't get this done, i always end up with an unable to find template error. I find the documentation on this subject a bit sparse (see http://symfony.com/doc/current/book/templating.html#including-other-templates) also the twig docs can't help me out on this one. I'm not even sure if i can use the magic #Bundle notation or if i have to reside in the view folder as ../ notation is not allowed within the include tag.
I tried the following (and a couple of variations):
{{ include('#FashionMediaBundle/Resources/static/pricing.html') }}
I guess symfony cannot handle raw html in include but i could use a php template without any template tags as well, so the question is just how to specify a location outside the view folder.
I know of http://github.com/kgilden/KGStaticBundle which will probably solve my issue but i can't believe that is not achievable with the default configuration.
EDIT: i just tried to include a regular template file from the very same directory specifying just the name of the template file (as done in the docs, see link above). Still i get an error also complaining it expects bundle:section:template.format.engine as its format. Is there an error in the docs?
Looks like the poster found the solution while I was typing. I guess I'll leave this here for just a bit.
Creating and using twig namespaces is discussed here: http://symfony.com/doc/current/cookbook/templating/namespaced_paths.html
By default, each bundles get's it's own namespace pointing to the views directory. You can add additional directories by adjusting app/config.yml
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
paths:
"%kernel.root_dir%/../../cerad2/src/Cerad/Bundle/FashionMediaBundle/Resources/static": FashionMedia
Load the template with: '#FashionMedia/pricing.html'
I won't go into all the details but you can also use a compiler pass(http://symfony.com/doc/current/cookbook/service_container/compiler_passes.html) to add additional paths from inside the bundle itself without having to adjust config.yml:
class Pass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$bundleDirAction = $container->getParameter('cerad_api01__bundle_dir') . '/Action';
$twigFilesystemLoaderDefinition = $container->getDefinition('twig.loader.filesystem');
$twigFilesystemLoaderDefinition->addMethodCall('addPath', array($bundleDirAction, 'CeradApi01'));
}
}
Try this:
{{ include('FashionMediaBundle:Resources:static:pricing.html') }}
If you want to put this file in another directory I suggest you to use a symbolic link (I don't know if Twig can include a file which is not in the Resources directory).
I found the Solution!
In the twig configuration you can set paths and assign a name to them.
twig:
[... twig options here ...]
paths:
"%kernel.root_dir%/../[path to static]": static_pages
And then you can include them in
{% include "#static_pages/pricing.html.twig" %}

How to load css file in JavaFX 2?

Wrote my JavaFX classes in com.xyz.abc package (ex: com.xyz.abc.Sample.java)
and wrote my CSS files in `root/css/styles.css.
How do I load this CSS file into Sample.java?
Add it to your scene at the begining of your app
scene.getStylesheets().add("path/to/your/stylesheet.css");
See the CSS reference guide for how paths are resolved:
A style sheet URL may be an absolute URL or a relative URL. If a
relative URL is given, it is resolved against the base URL of the
ClassLoader of the concrete Application class. If, for example, there
is a main class com.wicked.cool.ui.Main that extends Application, the
relative URL "com/wicked/cool/resources/styles.css" would resolve
correctly. The relative URL "../resources/styles.css" would not since
the path ".." relative to the root is not a valid path. It is often
easier to use the ClassLoader of some class to find the resource. For
example, if the "styles.css" file resides in the same package as Main,
the following code will give the correct URL:
com.wicked.cool.ui.Main.class.getResource("styles.css").toExternalForm()
Note that, beginning with JavaFX 2.1, a URL consisting of only an
absolute path (having no scheme or authority) is resolved relative to
the base URL of ClassLoader of the class that extends Application. In
other words, "/com/wicked/cool/resources/styles.css" is treated as
"com/wicked/cool/resources/styles.css". This is consistent with FXML.
So your question isn't quite clear, but if "root" is the classpath of your application, you probably want
scene.getStylesheets().add(getClass().getResource("css/styles.css").toExternalForm());
If "root" is actually a directory in the classpath, then replace "css/styles.css" with "root/css/styles.css".

inheritance with bundles changes the routes?

I have just created a new bundle and its route : it works fine.
Now I would like this bundle to inherit from another bundle I have : I add this method to the bundle class :
public function getParent() {
return 'DemoAsseticGestionRessourcesBundle';
}
and suddenly Symfony does not recognize the route and says that it does not exist anymore (the same route).In fact it uses the parent route to go to the new bundle I created and so I cannot use the parent bundle anymore.
Why ?
How should I do ?
(I would like to keep the routes to their owner.)
Note : I use yml
Thanks to you all
Note2: my routes
demo_gestion_bundle_homepage ANY ANY ANY /GestionBundle/
demo_assetic_gestion_ressources_homepage ANY ANY ANY /AsseticGestionRessources/
So to be clear : when I do /GestionBundle it does not work anymore and when I do /AsseticGestionRessources it leads to the GestionBundle
Check your routing.yml file paths. If these have the same paths, you overwrite the parents routing.yml file.
So if your parentBundle has the routing.yml file located at src/ParentBundle/Resources/config/routing.yml and the childBundle has the routing.yml file located at src/ChildBundle/Resources/config/routing.yml, it's not gonna work.
It's nice if you post your app/console router:debug output here

Override templateNameParser class with the custom bundle's config file?

I want to override the templating.name_parser.class but I would like to do some within the custom config bundle which is loaded after the FrameworkBundle. Right now what I do is:
place the config file inside the customBundle/Resources/config/
Re-run the templating pass by adding this to the custom bundle:
$container->addCompilerPass(new TemplatingPass());
I wonder if this is the best way to do so? (I know I can place the config inside the app/config) but I would like to place this config inside the customBundle if possible to make sure all the bundle's specific config is placed inside the package.

How to set up the path to my custom Gas3 template?

Gas3 is not able to find my custom template.
I replaced the default path:
class:org/granite/generator/template/remoteBase.gsp
With my file, like this:
class:myPackage/remoteBase.gsp
But every time Gas3 tries to create the .as of my classes I get a Resource not Found exception.
I tried different paths but all gave me the same error.
Found out that the path to the custom template has to be declared differently.
Like this:
file:///myPackage/remoteBase.gsp

Resources