How to add an html file to prouve ownership of a domaine in a Symfony application ?
Here is my working solution but I think it's pretty ugly because :
I have to create a special route
I have to store the file outside of /web directory where I think it is supposed to live.
Step 1 - Create a route (src/mybundle/Ressources/config/routing.xml
my_route_name:
path: /google43d423494a0981c2.html
defaults: { _controller: MyBundle:Main:googleCheck}
Step 2 - Create a controler action
public function googleCheckAction(){
return $this->render('google43d423494a0981c2.html.twig');
}
/!\ Carreful - trick 1 you need to rename the file with the .twig extention otherwise this won't work.
Now put the file under app/Resources/views/
You can also put the file in any of your bundle views, just change the path in the controler action.
What would be the best way to handle this case ?
Three options:
Just put a HTML file in the web/ folder and let the web server render it.
If necessary, you can store it outside of the Symfony project, and just tell your web server where to find it.
Alternatively, create a route in routing.yml and [serve it using the default controller] (http://symfony.com/doc/current/cookbook/templating/render_without_controller.html) and store the template in the root of app/Resources/views.
gwt:
path: /google43d423494a0981c2.html
defaults:
_controller: FrameworkBundle:Template:template
template: '::google43d423494a0981c2.html.twig'
I personally would choose option #2, because I wouldn't want to add a file which had nothing to do with the application into the repository.
Related
I have added a path entry in Twig config so I can also use template located in this folder:
twig:
paths:
'%kernel.project_dir%/modules': Modules
I would like to disable the cache only for this path, is this possible ?
If I do:
twig:
cache: false
Then caching is disabled for all templates, even the default path (ie the files inside app/templates/...)
Another person will update these templates regularly and I want the app to take the changes into account without him having to call me to empty the Symfony cache (he has an ftp access to the template folder, but he has no access to the Symfony console to clear the cache)
I have 7 bundles in my project. So I pointed each from main routing file (app->config->routing.yml).
I have a requirement that same routing file inside a bundle can able to be called using different paths. Like one path with an argument and other without argument.
My main routing file looks like as follows
clubadmin_general:
resource: "#TestGeneralBundle/Resources/config/routing.yml"
host: "mywebsite"
prefix: /{url_identifier}/admin/
clubadmin_general_club_domain:
resource: "#TestGeneralBundle/Resources/config/routing.yml"
prefix: /admin/
The routing file inside the bundle is common when called form main routing file. The routing file inside the bundle is looks like..
show_dashboard:
pattern: /
defaults: { _controller: TestGeneralBundle:Dashboard:index }
When I called, routing defined first gives "No route found". But the second works well. When I changed the order, always second works well.
In the above code path "/admin/" works well. But path "/{url_identifier}/admin/" will not work.
I think "show_dashboard" name is cached for a route. May be that is the issue. But couldn't find a solution.
Someone please help me.
Finally found a solution... By create different environment, the cache folder get separated and then can able to use same routing names with different paths.
I have an annoying problem with folder names and routes in ASP .NET Mvc 5,
This is the default routes I'm using:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Site", action = "Index", id = UrlParameter.Optional }
);
And I'm also using a custom view engine to map views to the root folder instead of ~/Views so I can have HTML/CSS/JS files organized in a way my team can handle.
The problem is: When I call /Backoffice/Index it goes normally and executes action Index in controller Backoffice, all fine, but when we call /Backoffice, I expected it to presume the action index (by the route configuration), but instead, IIS seems to believe I'm trying to access the folder /Backoffice and gives me a 404 error instead of executing Backoffice::Index().
How can I configure IIS to behave in the intended way in this case? Or, is it really the only best way to keep views in a specific folder?
I did some research and used info from the comments and answers here and got to learn something about how MVC routes work and how IIS handles that.
When we set
routes.RouteExistingFiles = true;
The MVC runtime will ignore every file in the folder and start using the routes and URIs solely to look for controllers and actions, this means by calling /SomeContent it will search for a controller named Somefolder instead of a folder. Then we can configure to serve static content by telling MVC runtime to ignore some specific URI formats:
routes.IgnoreRoute("SomeContent/CSS/{filename}.min.css");
routes.IgnoreRoute("SomeContent/JS/{filename}.min.js");
This causes MVC to ignore URIs that match this pattern and leave it for IIS to resolve what to do with it, then IIS will look out on Web.Config rather there are configurations set to serve this kind of static content and what handler to use and proceeed as usual.
Using this configuration can bring MVC to a whole new level of control where you explicitly define which URI patterns serve static content, everything else explicitly calls an action on a controller, all URIs get to be firstly processed by MVC runtime. I sure wish someone correct me in this last statement if I get it wrong.
MVC routes certain actions based on whether they exist on disk. If you have a folder /BackOffice at the root level, then this appears to be a complication that MVC is going to have issues working around (I knew files were directly routed if they existed; I didn't realize folders were something the framework checked too). Consider renaming the folder or the controller to something else so you don't have this naming conflict. That is a problem with "by convention" approaches....
I deployed my app in example.com/app but all my routes are broken.
Oops, looks like there's no route on the client or the server for url: "http://example.com/app/."
I can try to manually prepend to all routes /app/ subfolder but it doens't seem the right approach, especially since i use a cms package (orionjs) to generate the /admin interface, which doesn't have support to change the admin path.
Is there any way to prepend the /app folder to all routes by default?
What i find strange is that i defined ROOT_URL to http://example.com/app/ but iron router seems to ignore it. Did i skip a step ?
Unlike many web platforms (ex: php), the folder structure under your app does not map automatically to routes. If you're using iron-router you basically define what layout maps to what route. The layout can be defined in an HTML file in any folder (except under /server or /public) at any depth. You can also add any extra depth you want to any route in iron-router by prepending app/ or whatever you want to your route definitions. Your ROOT_URL should remain http://example.com/
I installed Symfony CMF structure bundles on my project, but default route is on
localhost/project/web/app_dev.php/
and i want to show it on
localhost/project/web/app_dev.php/cms
Thank you!!
So you do want to install symfony at the webroot, right? If that is the case, your best bet is to add a route /cms and add everything else under that route, instead of directly to the root. When using the RoutingAutoBundle, this should be no problem to configure. If your editors create routes themselves, you would need to work with the widget for selecting the parent of the routes to only propose the cms/ route you created - unless you think it could make sense for them to occasionally place a route outside of /cms.
If you want to be more strict, i think your best bet is the upcoming ResourceBundle. Discuss this with Dan over at https://groups.google.com/forum/#!topic/symfony-cmf-devs/6Wha2o3qHPE
Not sure if I understood your question. If you want your default home page at localhost/project/web/app_dev.php/ pointing to your cmf bundle, just add this at the begining of app/config/routing.yml
homepage:
pattern: /
defaults: { _controller: YourCMFBundle:Welcome:index }
Where Welcome is the name of your CMF default controller.