I am using Symfony 2.8 and I import my translations into the database with the help of the Lexik translation bundle - this allows me to have a route like /admin/translations where i can see statistics and add more translations (well, the customer will).
The problem is that this route has no security at all. I can just access it without even being logged in. I have an annotation that makes sure you have a certain role in order to access the given route.
My question is how can I add my custom annotation to the lexik controller that renders the translation templates (like overview and grid pages) without actually writing code inside the bundle (vendor folder). Is there a way to add it in the config?
In your security.yml you just need to add access control on the admin path
access_control:
- { path: ^/admin, role: ROLE_ADMIN }
Related
I have my routing.yml file and inside it i define the the routing files of all the application's bundles.
test_route:
resource: "#test/routing.yml"
prefix: /
test_route_2:
resource: "#test_2/routing.yml"
prefix: /
What i want to achieve is to enable the previous routes only under a custom condition. I want to pass a function there so i can make some complicated checks.
I don't know is Symfony supports this, so any kind of help/idea is welcome.
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.
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.
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.
How can I promote a user to ROLE_ADMIN in FOS_User_Bundle using phpmyadmin?
I am running mamp and can't get the MB function to work properly, so I just want to promote the user directly in the database. There's a field called roles, comment: (DC2Type:array), content a:0:{}.
This is what roles looks like when only ROLE_ADMIN is granted:
a:1:{i:0;s:10:"ROLE_ADMIN";}.
For reference, this is what it looks like with an additional role:
a:2:{i:0;s:10:"ROLE_ADMIN";i:1;s:9:"ROLE_USER";}.
Managing roles by directly editing the field in PHPMyAdmin is going to be annoying and prone to error, though. You should either use php app/console fos:user:promote. Or, since it looks like it's just a serialized array, you could write a quick script to update the field.