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.
Related
I'm starting to develop a project that will be quite big (hear lots of files) and I want to have an organization that's different from Symfony's default one: instead of having one dir for all my controllers, another for all my forms, etc, I want to have one dir per functionality, ie a directory for my homepage which will contain the controller, the templates, another dir for the blog page with the controller, forms and templates, and so on.
I tried what was explained in this (old) answer, and it didn't work : my routes weren't recognized, and a php bin/console debug:router showed they weren't listed anymore.
I feel I will have something to adapt in my routes.yaml file, which looks like this for now, and which explains why it doesn't work because it explicitely searches in the src\Controller directory:
controllers:
resource:
path: ../src/Controller/
namespace: App\Controller
type: attribute
I looked in the documentation I found, but I didn't find anything useful (I think I will have to remove the path and change it to something else, but I don't know what yet.
The above solutions are only for differentiating controller and template files. But For Entity, Events, and Forms it will not work.
It seems like you want to separate files for each module or functionality. For example, settings.yaml, controller, entity, forms, events, etc...
For that Symfony provides a Bundle feature. You can create a new Bundle in Symfony and use it as a separate feature. For more details please read this link
Scenario:
I want to implement user editable app settings in my symfony application but don't know what's the best practice.
The user should be able to edit global settings like company address or alike in the app backend, no user specific settings.
I had a look at the CraueConfigBundle, but I think a file based settings solution fits more to my problem.
It's difficult to find something on Google for my problem, maybe you can help me find that out.
What do you use to give your app admins the possibility to edit global settings?
For basic CraueConfigBundle can work for you (didn't use it just read docs) even tho it's saving to database.
Do you have particular reason why you need saving into file? You can always set up case to save data from database to file.
But if you want to write something in general, its require few steps like basically like this:
You need service which provide reading / uploading of configuration
This service can take use of adapters to do real Saving reading from your chosen source of data (for example you can use symfony Yaml component which can read / dump data from Yaml)
Then you need write user interface which suits your needs for that
I wanna build a simple permission system using symphony 4 that has the following properties:
there are several possible roles for users (SUPER_ADMIN, ADMIN, USER,QUEST)
SUPER_ADMIN users can grant view or edit&delete permissions for a given entity to a certain user no mater what his role is
What is the best solution for this?
Thanks
Please, start reading these documentations to figure out some basics :
SF4 Authorization
SF4 Security
SF4 Voters
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 }
I 'm a new with Symfony2!. Can you tell me please if I can user CRUD with FOSUserBundle?? Is that even possible ? Actually, i want create a Manager role who can edit and delete users form database !
FosUserBundle doesn't provide such functionality. You can generate CRUD using Symfony standard edition built in task:
php app/console doctrine:generate:crud
for your User entity.
For more complex purposes you need to check some admin bundles, maybe SonataAdminBundle . This will provide admin generator in which you can manage (CRUD) your entities.
Also note, that using all kinds of code generators is considered as not-so-good-practice
For those who are facing this issue :
- if you override the parent classe with custom fields (let's say "firstname" + "lastname") in you User entity
- and then re-generate the CRUD
you will see that the 2 custom field became editable.
The Doctrine CRUD generator looks incompatible with FOSUserBundle in the present state, as we create inheritance with a User master class.
There is a same issue if you try to use the Group Model of FOSUserBundle.