I make user of the Sonata User Bundle. According to the documentation under section 2.5 Extending the Bundle they want me to generate a complete new bundle for my user and group entities. I think this is completely unnecessary and I don't want that extra bundle. So I've created my User and Group entities in my AppBundle and I extend them from the Sonata\UserBundle\Entity\BaseUser entities.
After this, I've changed my fos_user user_class and group_class to my new entities.
fos_user:
db_driver: orm
firewall_name: main
user_class: AppBundle\Entity\User
group:
group_class: AppBundle\Entity\Group
group_manager: sonata.user.orm.group_manager
service:
user_manager: sonata.user.orm.user_manager
Everything works perfectly, my user and group tables in my database is generated correctly, I can create users through the fos user command line, and I can log in.
In the menu is an automatically generated user group that contain the user and group entities (see the image below). Now the only problem is to override the services for this entities to them to use my own entity classes, because when I click now on one of them they want the entities in the extended bundle that I don't want. How can I tell sonata to make use of my own services? Or even, how can I just remove or hide the Users (with Users and Groups) completely?
After some digging in Sonata User Bundle files, I see that the entities can be set with a parameter. So all I had to do was to add;
parameters:
sonata.user.admin.user.entity: AppBundle\Entity\User
sonata.user.admin.group.entity: AppBundle\Entity\Group
in my config.yml file.
"Or even, how can I just remove or hide the Users (with Users and Groups) completely?"
So, we have SonataUserBundle and our AppBundle.
In both of them we have User and Group Entity. And we don't want to use entities from sonata - we just extend them. But SonataUserBundle has already had the UserAdmin and GroupAdmin classes inside.
That's why, after installing SonataUserBundle in the admin menu appear two services:
As you know, every sonata admin class we declare in the services.yml file.
In SonataUserBundle we have another files, which sonata developers declare services in. In case of using doctrine orm we should look at admin_orm.xml file, which lies in this path:
vendor/sonata-project/user-bundle/Resources/config/admin_orm.xml
Inside the file we can find the declaration of the admin services - UserAdmin and GroupAdmin:
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="sonata.user.admin.groupname">sonata_user</parameter>
<parameter key="sonata.user.admin.label_catalogue">SonataUserBundle</parameter>
<parameter key="sonata.user.admin.groupicon"><![CDATA[<i class='fa fa-users'></i>]]></parameter>
</parameters>
<services>
<service id="sonata.user.admin.user" class="%sonata.user.admin.user.class%">
<tag name="sonata.admin" manager_type="orm" group="%sonata.user.admin.groupname%" label="users" label_catalogue="%sonata.user.admin.label_catalogue%" label_translator_strategy="sonata.admin.label.strategy.underscore" icon="%sonata.user.admin.groupicon%"/>
<argument/>
<argument>%sonata.user.admin.user.entity%</argument>
<argument>%sonata.user.admin.user.controller%</argument>
<call method="setUserManager">
<argument type="service" id="fos_user.user_manager"/>
</call>
<call method="setTranslationDomain">
<argument>%sonata.user.admin.user.translation_domain%</argument>
</call>
</service>
<service id="sonata.user.admin.group" class="%sonata.user.admin.group.class%">
<tag name="sonata.admin" manager_type="orm" group="%sonata.user.admin.groupname%" label="groups" label_catalogue="%sonata.user.admin.label_catalogue%" label_translator_strategy="sonata.admin.label.strategy.underscore"/>
<argument/>
<argument>%sonata.user.admin.group.entity%</argument>
<argument>%sonata.user.admin.group.controller%</argument>
<call method="setTranslationDomain">
<argument>%sonata.user.admin.group.translation_domain%</argument>
</call>
</service>
</services>
As you can see here the ids of our services:
sonata.user.admin.user
sonata.user.admin.group
The simplest method to overwrite them is to create the same services (I mean we will use this ids ) in our services.yml file.
Yes, you can have an argument with me, that this method is stupid, but as I said it's not the only one.
So Sonata services in OUR services.yml will looks like this:
sonata.user.admin.user:
class: "%sonata.user.admin.user.class%"
arguments: [~, "%sonata.user.admin.user.entity%", "%sonata.user.admin.user.controller%"]
tags:
- { name: sonata.admin, manager_type: orm, group: "%sonata.user.admin.groupname%", label_catalogue: "%sonata.user.admin.label_catalogue%", label: "users", icon: "<i class=\"fa fa-users\"></i>" }
calls:
- [ setUserManager, [ "#fos_user.user_manager" ] ]
- [ setTranslationDomain, [ "%sonata.user.admin.user.translation_domain%" ] ]
sonata.user.admin.group:
class: "%sonata.user.admin.group.class%"
arguments: [~, "%sonata.user.admin.group.entity%", "%sonata.user.admin.group.controller%"]
tags:
- { name: sonata.admin, manager_type: orm, group: "%sonata.user.admin.groupname%", label_catalogue: "%sonata.user.admin.label_catalogue%", label: "groups" }
calls:
- [ setTranslationDomain, [ "%sonata.user.admin.group.translation_domain%" ] ]
Now you can update the admin dashboard and see, that nothing have happened. But the our purpose was to disable this service from our dashboard and menu. Let's do the trick. Add
show_in_dashboard: false
tags:
- { show_in_dashboard: false, name: sonata.admin, manager_type: orm, group: "%sonata.user.admin.groupname%", label_catalogue: "%sonata.user.admin.label_catalogue%", label: "users", icon: "<i class=\"fa fa-user\"></i>" }
to the declaration of this service in services.yml.
Therefore our services will look like this:
sonata.user.admin.user:
class: "%sonata.user.admin.user.class%"
arguments: [~, "%sonata.user.admin.user.entity%", "%sonata.user.admin.user.controller%"]
tags:
- { name: sonata.admin, manager_type: orm, group: "%sonata.user.admin.groupname%", label_catalogue: "%sonata.user.admin.label_catalogue%", label: "users", icon: "<i class=\"fa fa-user\"></i>", show_in_dashboard: false }
calls:
- [ setUserManager, [ "#fos_user.user_manager" ] ]
- [ setTranslationDomain, [ "%sonata.user.admin.user.translation_domain%" ] ]
sonata.user.admin.group:
class: "%sonata.user.admin.group.class%"
arguments: [~, "%sonata.user.admin.group.entity%", "%sonata.user.admin.group.controller%"]
tags:
- { name: sonata.admin, manager_type: orm, group: "%sonata.user.admin.groupname%", label_catalogue: "%sonata.user.admin.label_catalogue%", label: "groups", show_in_dashboard: false }
calls:
- [ setTranslationDomain, [ "%sonata.user.admin.group.translation_domain%" ] ]
After this trivial manipulations Sonata services will completely disappear from your Dashboard.
I finished installing sonata-admin bundle + fosuser bundle.
after creating users using the command line , i found out that when i login using admin admin its gives me bad credentials , so after debugging for a while i found out that the fos:user:create save users to fos_user_user not user table .
how to fix this and make the fos:user:create save created users in user table .
here is a snippet of my config.yml
fos_user:
db_driver: orm
firewall_name: main
user_class: Application\Sonata\UserBundle\Entity\User
#user_class: Sizar\JobeetBundle\Entity\SizarUser
group:
group_class: Application\Sonata\UserBundle\Entity\Group
sonata_user:
class: # Entity Classes
user: Application\Sonata\UserBundle\Entity\User
if needed any configs then i will add it in the comments below
the User.php class
namespace Application\Sonata\UserBundle\Entity;
use Sonata\UserBundle\Entity\BaseUser as BaseUser;
class User extends BaseUser {
protected $id;
public function __construct() {
parent::__construct();
}
public function getId() {
return $this->id;
}
}
the orm User file
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Application\Sonata\UserBundle\Entity\User" table="fos_user_user">
<id name="id" column="id" type="integer">
<generator strategy="AUTO" />
</id>
</entity>
</doctrine-mapping>
You will have to update you mapping config, so that doctrine knows which table it is mapped to
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping ...>
<entity name="Application\Sonata\UserBundle\Entity\User" table="fos_user_user">
...
</entity>
</doctrine-mapping>
Here you will need to update the "table" property to the correct database table. Possibly you will need to recreate the database.
See FosUserBundle - Install docs for further info about the setup of your entities for the usage with FosUserBundle
I am just trying to get working LiipImagineBundle.
Ok, all I got so far:
Installed using composer
$ php composer.phar require "liip/imagine-bundle:dev-master"
Enabled bundle in AppKernel.php
new Liip\ImagineBundle\LiipImagineBundle(),
Added to routing.yml
_imagine path
Added liip_imagine filter in config.yml
Checked using php app/console router:debug and path _imagine_my_thumb exist.
But after using:
<img src="{{ '/relative/path/to/image.jpg' | imagine_filter('my_thumb') }}" />
image is not rendered, path is simply not found error.
prod.log says that Route _imagine_my_thumb does not exist, although it exist, because it's displayed using router:debug for both environments.
You know that you should replace '/relative/path/to/image.jpg' with your image path?
Make sure your file exists.
A working example
config:
liip_imagine:
driver: gd
web_root: %kernel.root_dir%/../web
data_root: %kernel.root_dir%/../app
cache_mkdir_mode: 0777
cache_prefix: /media/cache
cache: web_path
cache_clearer: true
data_loader: filesystem
controller_action: liip_imagine.controller:filterAction
formats: []
filter_sets:
avatar:
filters:
thumbnail: { size: [40, 40], mode: outbound }
profile:
filters:
relative_resize: { widen: 500 }
html:
<img src="{{ 'uploads/images/filename.jpg' | imagine_filter('avatar') }}" alt="image">
enter code here
routing.yml:
_imagine:
resource: .
type: imagine
Remark: My source folder is in the app folder (see: data_root)
I had similar problem and after enable of php_fileinfo extension in php.ini render start to work.
I'm using Symfony 2.1 dev and looking for easiest way to get parameter from app/config/parameters.yml (ini).
Simple example:
I have record in parameters.yml
parameters:
url: "http://domain.com"
Then i want to use it somehow in static js file
var url = "{{ app.url }}"; // trying to avoid hardcode
This token should be replaced by actual value from coonfig after
app/console assetic:dump
So final js will have
var url = "http://domain.com";
Currently i'm thinking about writing my own console command but firstly i want to ensure there is no any standard way of doing such things in Symfony2 or maybe some bundle that can halp me?
UPDATE: i'd like to do this with AsseticBundle, like YUI and LESS
assetic:
debug: %kernel.debug%
use_controller: false
write_to: %kernel.root_dir%/../web
filters:
cssrewrite: ~
lessphp: ~
yui_js:
jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.6.jar"
yui_css:
jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.6.jar
to add another one filter which will replace token {{ app.url }} in js file to actual "http://domain.com"
A simple solution would be to reference your parameters in the twig globals:
parameters:
url: "http://domain.com"
an_array:
twig: "is cool"
and: "symfony2 to"
twig:
globals:
app_parameters:
url: %url%
an_array: %an_array%
Then in your template:
<script>
window.parameters = {{ app_parameters|json_encode|raw }};
</script>
would render something like:
<script>
window.parameters = {"url":"http://domain.com","an_array":{"twig":"is cool","and":"symfony2 to"}};
</script>
I followed official tutorials to install FOSUser then SonataUser bundles and my app/Application/Sonata/UserBundle/Entity extension.
Now I'm having 4 tables: fos_user, fos_user_group, fos_user_user and fos_user_user_group.
my security.yml
security:
providers:
fos_userbundle:
id: fos_user.user_manager
my config.yml
fos_user:
db_driver: orm
firewall_name: main
user_class: Me\UserBundle\Entity\User
# user_class: Application\Sonata\UserBundle\Entity\User
my /app/Application/Sonata/UserBundle/Resources/config/doctrine/User.orm.xml
...
<entity name="Application\Sonata\UserBundle\Entity\User" table="fos_user_user">
<id name="id" column="id" type="integer">
<generator strategy="AUTO" />
</id>
</entity>
...
I also have created my UserBundle like it's written fosuser docs.
So users are authenticated with fos_user but sonata admin shows users from fos_user_user
What could be wrong in my config ?
I've spend couple of hours founding that both fos_user and sonata_user should be registred in config.yml:
fos_user:
db_driver: orm
firewall_name: main
user_class: App\UserBundle\Entity\User
group:
group_class: App\UserBundle\Entity\Group
sonata_user:
class:
user: Me\UserBundle\Entity\User
group: Me\UserBundle\Entity\Group
I finally restarted the whole FOSUser & SonataUser/Admin installation by following this good tutorial step by step.
I think my error was to extend FOSUser with my bundle while Sonata extends it already with easy extend.
So I completely removed my UserBundle.