symfony2.6 route with query params (KnpPaginatorBundle and WhiteOctoberPagerfantaBundle) - php

Trying to use KnpPaginatorBundle and WhiteOctoberPagerfantaBundle
If i have url
/categories/tech/plates
next page url show me
/catalog/categories/tech/plates?/catalog/categories/tech/plates=&page=2
I can not understand why this is happening :(
Can anyone help?
What am I doing wrong?
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
// default symfony project
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
// additional
// new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
new SimpleThings\EntityAudit\SimpleThingsEntityAuditBundle(),
new Sonata\IntlBundle\SonataIntlBundle(),
new FOS\JsRoutingBundle\FOSJsRoutingBundle(),
new A2lix\TranslationFormBundle\A2lixTranslationFormBundle(),
new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
new Bazinga\Bundle\JsTranslationBundle\BazingaJsTranslationBundle(),
// admin panel
new Sonata\CoreBundle\SonataCoreBundle(),
new Sonata\BlockBundle\SonataBlockBundle(),
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
new Sonata\AdminBundle\SonataAdminBundle(),
new Application\Sonata\AdminBundle\ApplicationSonataAdminBundle(),
new Sonata\MediaBundle\SonataMediaBundle(),
new CoopTilleuls\Bundle\CKEditorSonataMediaBundle\CoopTilleulsCKEditorSonataMediaBundle(),
new Application\Sonata\MediaBundle\ApplicationSonataMediaBundle(),
// // users
new FOS\UserBundle\FOSUserBundle(),
new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
new Sonata\EasyExtendsBundle\SonataEasyExtendsBundle(),
new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
new FOS\OAuthServerBundle\FOSOAuthServerBundle(),
new Application\FOS\OAuthServerBundle\ApplicationFOSOAuthServerBundle(),
// new HWI\Bundle\OAuthBundle\HWIOAuthBundle(),
// new Xxx\Bundle\OAuthUserBundle\XxxOAuthUserBundle(),
// rest api default
new FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
new Application\FOS\RestBundle\ApplicationFOSRestBundle(),
// form
new Ivory\OrderedFormBundle\IvoryOrderedFormBundle(), //order fields with 'position' attribute
//form types
new Genemu\Bundle\FormBundle\GenemuFormBundle(),
new Stnw\DatePickerBundle\StnwDatePickerBundle(),
new Ivory\CKEditorBundle\IvoryCKEditorBundle(),
new Misd\PhoneNumberBundle\MisdPhoneNumberBundle(),
// charts
// new Ob\HighchartsBundle\ObHighchartsBundle(),
// grid
new APY\DataGridBundle\APYDataGridBundle(),
// new Lunetics\LocaleBundle\LuneticsLocaleBundle(),
new JMS\I18nRoutingBundle\JMSI18nRoutingBundle(),
new JMS\TranslationBundle\JMSTranslationBundle(),
// project
new Xxx\Bundle\AppBundle\XxxAppBundle(),
new Xxx\Bundle\CompanyBundle\XxxCompanyBundle(),
new Xxx\Bundle\TransactionBundle\XxxTransactionBundle(),
new Xxx\Bundle\StoreBundle\XxxStoreBundle(),
new Xxx\Bundle\DeviceBundle\XxxDeviceBundle(),
new Xxx\Bundle\CatalogBundle\XxxCatalogBundle(),
new Xxx\Bundle\ChipBundle\XxxChipBundle(),
new Xxx\Bundle\CityBundle\XxxCityBundle(),
new Xxx\Bundle\LastActivityBundle\XxxLastActivityBundle(),
// frontend
new WhiteOctober\BreadcrumbsBundle\WhiteOctoberBreadcrumbsBundle(),
new Xxx\ContactBundle\XxxContactBundle(),
new Application\Xxx\ContactBundle\ApplicationXxxContactBundle(),
new Xxx\Bundle\FaqBundle\XxxFaqBundle(),
new Xxx\Bundle\NewsBundle\XxxNewsBundle(),
new Xxx\Bundle\MenuBundle\XxxMenuBundle(),
new Xxx\Bundle\PageBundle\XxxPageBundle(),
new Xxx\Bundle\SmsGatewayBundle\XxxSmsGatewayBundle(),
];
if (in_array($this->getEnvironment(), ['dev', 'test'])) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
// translator, needed for grid
$bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
// $bundles[] = new JMS\TranslationBundle\JMSTranslationBundle();
}
return $bundles;
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}
}
# app/config/config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: ../../vendor/knplabs/doctrine-behaviors/config/orm-services.yml }
framework:
#esi: ~
translator: { fallback: "%locale%" }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
exception_controller: 'FOS\RestBundle\Controller\ExceptionController::showAction'
form:
resources:
- 'StnwDatePickerBundle:Form:fields.html.twig'
- 'XxxAppBundle:Form:fields.html.twig'
globals:
locales: "%locales%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
types:
json: Sonata\Doctrine\Types\JsonType
phone_number: Misd\PhoneNumberBundle\Doctrine\DBAL\Types\PhoneNumberType
# if using pdo_sqlite as your database driver, add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
# spool: { type: memory }
sensio_framework_extra:
view:
annotations: false
fos_rest:
param_fetcher_listener: true
view:
view_response_listener: 'force'
formats:
xml: true
json: true
templating_formats:
html: true
format_listener:
rules:
- { path: ^/, priorities: [ html, json, xml ], fallback_format: ~, prefer_extension: true }
exception:
codes:
'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT
messages:
'Symfony\Component\Routing\Exception\ResourceNotFoundException': true
allowed_methods_listener: true
access_denied_listener:
json: true
# serializer:
# serialize_null: true
body_listener: true
disable_csrf_role: ROLE_API
nelmio_api_doc:
name: Xxx REST API
sandbox:
authentication:
delivery: http
# name: apiKey
type: bearer # `basic`, `bearer` are supported
sonata_block:
default_contexts: [cms]
blocks:
# Enable the SonataAdminBundle block
sonata.admin.block.admin_list:
contexts: [admin]
sonata.admin.block.search_result:
contexts: [admin]
# Your other blocks
sonata.user.block.menu: # used to display the menu in profile pages
sonata.user.block.account: # used to display menu option (login option)
sonata.block.service.text:
sonata.block.service.action:
sonata.block.service.rss:
sonata_admin:
title: Xxx
# title_logo: bundles/acmedemo/img/fancy_acme_logo.png
templates:
# default global templates
layout: ApplicationSonataAdminBundle::layout.html.twig
ajax: SonataAdminBundle::ajax_layout.html.twig
# default actions templates, should extend a global templates
list: SonataAdminBundle:CRUD:list.html.twig
show: SonataAdminBundle:CRUD:show.html.twig
edit: SonataAdminBundle:CRUD:edit.html.twig
search: SonataAdminBundle:Core:search.html.twig
search_result_block: SonataAdminBundle:Block:block_search_result.html.twig
dashboard:
blocks:
# display a dashboard block
- { position: left, type: sonata.admin.block.admin_list }
groups:
default:
fos_user:
label: menu.group_users
items: [sonata.user.admin.user, sonata.user.admin.group]
xxx_company:
label: menu.group_company
items: [xxx.admin.company, xxx.admin.company_category, xxx.admin.store, xxx.admin.device]
xxx_catalog:
label: menu.group_catalog
items: [xxx.admin.catalog.product, xxx.admin.catalog.product_category, xxx.admin.chip.rule]
xxx_transaction:
label: menu.group_transaction
items: [xxx.admin.transaction]
xxx_media:
label: menu.group_media
items: [sonata.media.admin.media]
xxx_news:
label: menu.group_news
items: [xxx.news.admin.news]
xxx_faq:
label: menu.group_faq
items: [xxx.faq.admin.faq]
xxx_page:
label: menu.group_page
items: [xxx_page.admin.page]
xxx_menu:
label: menu.group_menu
items: [xxx_menu.admin.menu, xxx_menu.admin.menu_type]
xxx_city:
label: menu.group_city
items: [xxx_city.admin.city]
xxx_sms_gateway:
label: menu.group_sms_gateway
items: [xxx_sms_gateway.admin.message]
security:
handler: sonata.admin.security.handler.role
# acl security information
information:
ADMIN: [MASTER]
# permissions not related to an object instance and also to be available when objects do not exist
# the DELETE admin permission means the user is allowed to batch delete objects
admin_permissions: [CREATE, LIST, DELETE, UNDELETE, EXPORT, OPERATOR, MASTER]
# permission related to the objects
object_permissions: [VIEW, EDIT, DELETE, UNDELETE, OPERATOR, MASTER, OWNER]
options:
html5_validate: true # does not use html5 validation
confirm_exit: false # disable confirmation when quitting with unsaved changes
use_select2: true # disable select2
pager_links: 5 # pager max links to display
# set to true to persist filter settings per admin module in the user's session
persist_filters: false
#read http://sonata-project.org/bundles/media/2-2/doc/reference/installation.html
sonata_media:
# if you don't use default namespace configuration
#class:
# media: MyVendor\MediaBundle\Entity\Media
# gallery: MyVendor\MediaBundle\Entity\Gallery
# gallery_has_media: MyVendor\MediaBundle\Entity\GalleryHasMedia
default_context: default
db_driver: doctrine_orm # or doctrine_mongodb, doctrine_phpcr
contexts:
default: # the default context is mandatory
providers:
# - sonata.media.provider.dailymotion
- sonata.media.provider.youtube
- sonata.media.provider.image
# - sonata.media.provider.file
formats: ~
small: { width: 100 , quality: 70}
big: { width: 500 , quality: 70}
cdn:
server:
path: /uploads/media # http://media.sonata-project.org/
filesystem:
local:
directory: %kernel.root_dir%/../web/uploads/media
create: false
# Notice: EntityAudit currently only works with a DBAL Connection and EntityManager named "default".
simple_things_entity_audit:
# таблицы мультиперевода автоматически НЕ цепляются, поэтому нужно указывать в ручную в этом списке
audited_entities:
- Application\Sonata\UserBundle\Entity\User
- Application\Sonata\UserBundle\Entity\Group
# If you need to exclude some entity properties from triggering a revision use:
# global_ignore_columns:
# - created_at
# - updated_at
sonata_intl:
timezone:
default: Europe/Moscow
detectors:
- sonata.intl.timezone_detector.user
- sonata.intl.timezone_detector.locale
locales:
ru: Europe/Chisinau
fos_user:
db_driver: orm # can be orm or odm
firewall_name: admin
user_class: Application\Sonata\UserBundle\Entity\User
from_email:
address: noreply#xxx.com
sender_name: Xxx Noreply
registration:
form:
type: application_sonata_user_registration
handler: fos_user.registration.form.handler.default
name: fos_user_registration_form
validation_groups: [XxxRegistration]
confirmation:
enabled: true
template: ApplicationSonataUserBundle:Registration:email.txt.twig
profile:
form:
type: application_fos_user_profile
handler: fos_user.profile.form.handler.default
name: fos_user_profile_form
validation_groups: [Authentication]
change_password:
form:
type: application_fos_user_change_password
handler: fos_user.change_password.form.handler.default
name: fos_user_change_password_form
validation_groups: [ChangePassword, Default]
group:
group_class: Application\Sonata\UserBundle\Entity\Group
group_manager: sonata.user.orm.group_manager # If you're using doctrine orm
service:
user_manager: sonata.user.orm.user_manager # If you're using doctrine orm
mailer: fos_user.mailer.twig_swift
sonata_user:
security_acl: false
class:
user: Application\Sonata\UserBundle\Entity\User
group: Application\Sonata\UserBundle\Entity\Group
profile: # Profile Form (firstname, lastname, etc ...)
form:
type: application_sonata_user_profile
handler: sonata_user.form.handler.profile
name: sonata_user_profile_form
validation_groups: [Profile]
impersonating:
route: sonata_admin_dashboard
parameters:
sonata.user.admin.user.class: Application\Sonata\UserBundle\Admin\UserAdmin
knp.doctrine_behaviors.blameable_listener.user_entity: Application\Sonata\UserBundle\Admin\UserAdmin
# sonata.user.admin.user.translation_xxxin: ApplicationUserBundle
fos_oauth_server:
db_driver: orm # Driver availables: orm, mongodb, or propel
client_class: Application\FOS\OAuthServerBundle\Entity\Client
access_token_class: Application\FOS\OAuthServerBundle\Entity\AccessToken
refresh_token_class: Application\FOS\OAuthServerBundle\Entity\RefreshToken
auth_code_class: Application\FOS\OAuthServerBundle\Entity\AuthCode
service:
user_provider: fos_user.user_manager
options:
access_token_lifetime: 3600 #seconds
token_type: Bearer
# supported_scopes: oauth_scope_scanner test1
fos_js_routing:
cache_control:
# All are optional, defaults shown
public: false # can be true (public) or false (private)
maxage: null # integer value, e.g. 300
smaxage: null # integer value, e.g. 300
expires: null # anything that can be fed to "new \DateTime($expires)", e.g. "5 minutes"
vary: [] # string or array, e.g. "Cookie" or [ Cookie, Accept ]
jms_serializer:
metadata:
auto_detection: true
directories:
SonataUserBundle:
namespace_prefix: "Sonata\\UserBundle"
path: "#ApplicationSonataUserBundle/Resources/config/serializer/SonataUserBundle"
FOSUserBundle:
namespace_prefix: "FOS\\UserBundle"
path: "#ApplicationSonataUserBundle/Resources/config/serializer/FOSUserBundle/"
white_october_pagerfanta:
exceptions_strategy:
out_of_range_page: to_http_not_found
not_valid_current_page: to_http_not_found
apy_data_grid:
limits: [20, 50, 100]
pagerfanta:
enable: true #default false
view_class: Pagerfanta\View\TwitterBootstrap3View #default Pagerfanta\View\DefaultView
options: #all options of pager fanta view constructor
prev_message : «
next_message : »
genemu_form:
date: ~
captcha: ~
# tinymce: ~
a2lix_translation_form:
locales: %locales% # [1]
required_locales: %locales% # [2]
manager_registry: doctrine # [3]
templating: "A2lixTranslationFormBundle::default.html.twig" # [4]
white_october_breadcrumbs:
viewTemplate: "XxxAppBundle:Breadcrumbs:breadcrumbs.html.twig"
separator: ""
ivory_ck_editor:
default_config: default
configs:
default:
filebrowserBrowseRoute: admin_sonata_media_media_browser
filebrowserImageBrowseRoute: admin_sonata_media_media_browser
# Display images by default when clicking the image dialog browse button
filebrowserImageBrowseRouteParameters:
provider: sonata.media.provider.image
filebrowserUploadRoute: admin_sonata_media_media_upload
filebrowserUploadRouteParameters:
provider: sonata.media.provider.file
# Upload file as image when sending a file from the image dialog
filebrowserImageUploadRoute: admin_sonata_media_media_upload
filebrowserImageUploadRouteParameters:
provider: sonata.media.provider.image
context: my-context # Optional, to upload in a custom context
xxx_transaction:
sms_confirmation: %transaction_sms_confirmation%
xxx_contact:
store_data: false
contact_class: Xxx\ContactBundle\Model\BaseContact
form:
type: application_xxx_contact
# handler: xxx_contact.form.handler.default
# name: contact_form
# validation_groups: [Default]
# subject_provider: xxx_contact.subject_provider.noop
captcha_type: genemu_captcha
#
email:
# mailer: xxx_contact.mailer.twig_swift
recipient_address: "%admin_email%" # Required
# template: XxxContactBundle:Contact:email.txt.twig
jms_i18n_routing:
default_locale: %locale%
locales: %locales%
strategy: prefix_except_default
xxx_sms_gateway:
monolog_handler: monolog.logger.sms_gateway
message:
class: Xxx\Bundle\SmsGatewayBundle\Entity\Message
manager: xxx_sms_gateway.entity.message_manager
default_gateway: bulk_sms
gateways:
bulk_sms:
sender: %sms_gateway_bulk_sms_sender%
username: %sms_gateway_bulk_sms_username%
password: %sms_gateway_bulk_sms_password%
mode:
charset: plaintext # plaintext, utf8, windows-1251
max_number_of_chars: 160 # 160 for plaintext, 70 for UTF8 and Windows 1251
# base_url: http://79.170.224.75/BulkSMSAPI/UnifunBulkSMSAPI.asmx/SendSMSNoneDigitsEncoded
base_url: http://79.170.224.75/BulkSMSAPI/UnifunBulkSMSAPI.asmx/SendSMSSimple
report:
enabled: false
mask: 31 # 1, 2, 4, 8, 16, 31
route: xxx_sms_gateway_sms_report_bulk_sms
bazinga_js_translation:
locale_fallback: %locale%
active_locales: %locales%
default_xxxin: XxxAppBundle
xxx_last_activity:
audited_entities:
# - Application\Sonata\UserBundle\Entity\User # при регистарции нет имени
- Xxx\Bundle\CompanyBundle\Entity\Company
- Xxx\Bundle\FaqBundle\Entity\Faq
- Xxx\Bundle\NewsBundle\Entity\News
Standart pagination with pagerfanta
{% if pagination.haveToPaginate %}
{{ pagerfanta(pagination, 'twitter_bootstrap3_translated') }}
{% endif %}
Standart pagination call
// return some query
$query = $this->getManager()->getQueryAllByCategory($findCompaniesByCategory);
$page = $request->query->get('page', 1);
$pagination = new Pagerfanta(new DoctrineORMAdapter($query));
$pagination
->setMaxPerPage($this->container->getParameter('items_on_page'))
->setCurrentPage($page)
;

Related

ClassNotFoundException: Attempted to load class "FOSUserBundle" from namespace "FOS\UserBundle"

(Using WampServer on Windows 10.)
I followed the official documentation in order to install Sonata User Bundle over Symfony.
I get the following error message
(1/1) ClassNotFoundException Attempted to load class "FOSUserBundle"
from namespace "FOS\UserBundle". Did you forget a "use" statement for
another namespace?
AppKernel.php
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
new Sonata\CoreBundle\SonataCoreBundle(),
//Added following https://sonata-project.org/bundles/admin/3-x/doc/getting_started/installation.html
new Sonata\BlockBundle\SonataBlockBundle(),
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
new Sonata\AdminBundle\SonataAdminBundle(),
//Added following https://sonata-project.org/bundles/easy-extends/2-x/doc/reference/installation.html
new Sonata\EasyExtendsBundle\SonataEasyExtendsBundle(),
//Added following https://sonata-project.org/bundles/user/3-x/doc/reference/installation.html
new FOS\UserBundle\FOSUserBundle(),
new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
];
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
if ('dev' === $this->getEnvironment()) {
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
}
}
return $bundles;
}
public function getRootDir()
{
return __DIR__;
}
public function getCacheDir()
{
return dirname(__DIR__).'/var/cache/'.$this->getEnvironment();
}
public function getLogDir()
{
return dirname(__DIR__).'/var/logs';
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
}
}
config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
#translator: { fallbacks: ['%locale%'] }
secret: '%secret%'
router:
resource: '%kernel.project_dir%/app/config/routing.yml'
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: '%locale%'
trusted_hosts: ~
session:
# https://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: session.handler.native_file
save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'
fragments: ~
http_method_override: true
assets: ~
php_errors:
log: true
# Twig Configuration
twig:
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: '%kernel.project_dir%/var/data/data.sqlite'
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
#path: '%database_path%'
types:
json: Sonata\Doctrine\Types\JsonType
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
entity_managers:
default:
mappings:
ApplicationSonataUserBundle: ~
SonataUserBundle: ~
FOSUserBundle: ~ # If SonataUserBundle extends it
# Swiftmailer Configuration
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }
#Sonata
sonata_core:
form_type: horizontal
sonata_user:
security_acl: true
manager_type: orm # can be orm or mongodb
sonata_block:
default_contexts: [cms]
blocks:
# enable the SonataAdminBundle block
sonata.admin.block.admin_list:
contexts: [admin]
#...
sonata.user.block.menu: # used to display the menu in profile pages
sonata.user.block.account: # used to display menu option (login option)
sonata.block.service.text: # used to if you plan to use Sonata user routes
#FOSUser
fos_user:
db_driver: orm # can be orm or odm
firewall_name: main
user_class: Sonata\UserBundle\Entity\BaseUser
group:
group_class: Sonata\UserBundle\Entity\BaseGroup
group_manager: sonata.user.orm.group_manager # If you're using doctrine orm (use sonata.user.mongodb.group_manager for mongodb)
service:
user_manager: sonata.user.orm.user_manager # If you're using doctrine orm (use sonata.user.mongodb.user_manager for mongodb)
routing.yml
login_view:
path: '/login/'
defaults: { _controller: AppBundle:Login:view }
singlesingon_view:
path: '/authentication/singlesignon/'
defaults: { _controller: AppBundle:AuthenticationSingleSignOn:view }
singlesingout_view:
path: '/authentication/singlesignout/'
defaults: { _controller: AppBundle:AuthenticationSingleSignOut:view }
app:
resource: '#AppBundle/Controller/'
type: annotation
admin_area:
resource: "#SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
prefix: /admin
sonata_user_admin_security:
resource: '#SonataUserBundle/Resources/config/routing/admin_security.xml'
prefix: /admin
sonata_user_admin_resetting:
resource: '#SonataUserBundle/Resources/config/routing/admin_resetting.xml'
prefix: /admin/resetting
When I reach step 2.5 which starts with running
php bin/console sonata:easy-extends:generate SonataUserBundle -d src
I get
Fatal error: Class 'FOS\UserBundle\FOSUserBundle' not found.
As requested in comments: autoload section of composer.json
"autoload": {
"psr-4": {
"AppBundle\\": "src/AppBundle"
},
"classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
},
In composer.json
"autoload": {
"psr-0": {
"": "src/",
"Application": "app/"
}
},
than Update Composer :
composer update
if this dont work so try to fix the bundle by this command :
php app/console sonata:easy-extends:generate --dest=src SonataMediaBundle
Extend base user FosUser :
class Myusers extends BaseUser
{
}
In config.yml
fos_user:
user_class: MyBundle\Entity\Myusers

FosUserBundle confirmation email doesn't work with swiftmailer

I want to use the fosuserbundle functionality to send confirmation email and retrieve password etc ... But it is not working. I'm currently working in dev environment on LAMP. I think It could be a config.yml issue but I tried everything...
I assume my config.yml file has to be cleaned up but I'm not sure about what I can delete and what I can't.
Here is my way too large config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: "#UserBundle/Resources/config/services.yml" }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: fr
framework:
#esi: ~
translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
filters:
softdeleteable:
class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
enabled: true
auto_mapping: true
mappings:
gedmo_translatable:
type: annotation
prefix: Gedmo\Translatable\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
alias: GedmoTranslatable # (optional) it will default to the name set for the mapping
is_bundle: false
gedmo_translator:
type: annotation
prefix: Gedmo\Translator\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translator/Entity"
alias: GedmoTranslator # (optional) it will default to the name set for the mapping
is_bundle: false
gedmo_loggable:
type: annotation
prefix: Gedmo\Loggable\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity"
alias: GedmoLoggable # (optional) it will default to the name set for the mappingmapping
is_bundle: false
gedmo_tree:
type: annotation
prefix: Gedmo\Tree\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"
alias: GedmoTree # (optional) it will default to the name set for the mapping
is_bundle: false
stof_doctrine_extensions:
orm:
default:
softdeleteable: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
#Login using email
security:
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
# FOSUserBundle Configuration
fos_user:
db_driver: orm
firewall_name: main
user_class: UserBundle\Entity\User
# Permet de définir quel service de mail utiliser
# On utilise twig_swift pour pouvoir envoyer un email en HTML
service:
mailer: fos_user.mailer.twig_swift
user_manager: pugx_user_manager
# Permet de renseigner le nouveau formulaire d'inscription
registration:
form:
type: app_user_registration
# Permet la validation automatique du compte par envoi d'un email
confirmation:
template: UserBundle:Registration:email.txt.twig
enabled: true
from_email:
address: gauthiercoste#gmail.com
sender_name: Gauthier Coste
resetting:
email:
from_email:
address: gauthiercoste#gmail.com
sender_name: Abracadavrac
pugx_multi_user:
users:
standard_user:
entity:
class: UserBundle\Entity\StandardUser
registration:
form:
type: UserBundle\Form\RegistrationStandardUserType
validation_groups: [Registration, Default]
seller:
entity:
class: UserBundle\Entity\Seller
registration:
form:
type: UserBundle\Form\RegistrationSellerType
name: fos_user_registration_form
validation_groups: [Registration, Default]
template: UserBundle:Registration:registerProStep1.html.twig
assetic:
debug: '%kernel.debug%'
use_controller: '%kernel.debug%'
filters:
cssrewrite: ~
parameters.yml :
# This file is auto-generated during the composer install
parameters:
database_host: 127.0.0.1
database_port: null
database_name: xxxxxxxxxx
database_user: root
database_password: xxxxxxxxxx
mailer_transport: gmail
mailer_host: 127.0.0.1
mailer_user: xxxxxxxxxx#gmail.com
mailer_password: xxxxxxxxxx
secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
My registration process is in my controller RegistrationStandardUserController.php
public function registerAction(Request $request)
{
$em = $this->get('doctrine.orm.entity_manager');
//Form creation based on my user entity
$user = new StandardUser();
$form = $this->createForm(RegistrationStandardUserType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$user ->setEnabled(true);
$em ->persist($user);
$em ->flush();
if (!$user) {
throw new UsernameNotFoundException("User not found");
} else {
$request->getSession()->getFlashBag()->add('success', 'Félicitation '.$user->getFirstName().', vous êtes inscrit');
$this->authenticateUser($user);
}
}else if($form->isSubmitted() && !$form->isValid()){
$request->getSession()->getFlashBag()->add('error', 'Il y a une erreur dans le formulaire d\'inscription');
}
return $this->render('UserBundle:Registration:register.html.twig', array(
'form' => $form->createView()
));
}
The confirmation mail is triggered by the REGISTRATION_SUCCESS event of FosUserBundle. In order to send the confirmation mail, I had to :
Activate the confirmation in config.yml
configure swift_mailer
dispense the REGISTRATION_SUCCESS event in my controller
When the controller is overrided, we must not forget to dispense the events.
$event = new FormEvent($form, $request);
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);

exception `Unable to find entity` after the addition of FOSUserBundle

I follow steps from my book (based on symfony 2.0.10, I'm using Symfony2.6.1 with FOSUB 2.0).
I build project with CRUD that display data from db just fine (Mountain controller inside My/BackendBundle).
Then I want display project only for logged user admin (with ROLE_SUPER_ADMIN, that exist in my for_user table inside db with CRUD data).
But when openning ../web/ its result exception Unable to find Mountain entity. from Mountain controller showAction($id)
#\src\My\BackendBundle\Controller\MountainController.php
/**
* Finds and displays a Mountain entity.
*
* #Route("/{id}", name="mountain_show")
* #Method("GET")
* #Template()
*/
public function showAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('MyBackendBundle:Mountain')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Mountain entity.');
}
$deleteForm = $this->createDeleteForm($id);
return array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(),
);
AppKernel.php
#\app\AppKernel.php
new FOS\UserBundle\FOSUserBundle(),
new My\UserBundle\MyUserBundle(),
new My\BackendBundle\MyBackendBundle(),
security.yml
#\app\config\security.yml
security:
providers:
fos_userbundle:
id: fos_user.user_manager
encoders:
FOS\UserBundle\Model\UserInterface: sha512
firewalls:
main:
pattern: ^/
logout: true
anonymous: true
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
login_path: /login
use_forward: false
check_path: /login_check
post_only: true
always_use_default_target_path: false
default_target_path: /
target_path_parameter: _target_path
use_referer: false
failure_path: null
failure_forward: false
username_parameter: _username
password_parameter: _password
csrf_parameter: _csrf_token
intention: authenticate
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, role: ROLE_SUPER_ADMIN }
config.yml
#\app\config\config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
framework:
#esi: ~
translator: ~
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# default_locale: pl
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
stof_doctrine_extensions:
default_locale: en_US
orm:
default:
tree: false
loggable: false
timestampable: false
sluggable: false
translatable: false
fos_user:
db_driver: orm
firewall_name: main
user_class: My\UserBundle\Entity\User
routing.yml
#\app\config\routing.yml
MyBackendBundle:
resource: "#MyBackendBundle/Controller/"
type: annotation
prefix: /
fos_user_security:
resource: "#FOSUserBundle/Resources/config/routing/security.xml"
parameters.yml
#\parameters.yml
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: null
database_name: koronaziemi
database_user: root
database_password: null
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
locale: pl
secret: ThisTokenIsNotSoSecretChangeIt
Add requirements parameter to your route description and also you can skip entity fetching by leaving it for Symfony to serve you:
#\src\My\BackendBundle\Controller\MountainController.php
/**
* Finds and displays a Mountain entity.
*
* #Route("/{mountain}", name="mountain_show", requirements={"mountain": "\d+"})
* #Method("GET")
* #Template()
*/
public function showAction(Mountain $mountain)
{
$deleteForm = $this->createDeleteForm(mountain->getId());
return array(
'entity' => $mountain,
'delete_form' => $deleteForm->createView(),
);
}
Also, #Template() considered as bad practice and it is a better idea to return a Response object:
#\src\My\BackendBundle\Controller\MountainController.php
/**
* Finds and displays a Mountain entity.
*
* #Route("/{mountain}", name="mountain_show", requirements={"mountain": "\d+"})
* #Method("GET")
*/
public function showAction(Mountain $mountain)
{
$deleteForm = $this->createDeleteForm(mountain->getId());
return $this->render(
'MyBackendBundle:Mountain:show',
array(
'entity' => $mountain,
'delete_form' => $deleteForm->createView(),
)
);
}
----edit---
#Aistis with this code
/**
* #Route("/{id}", name="mountain_show", requirements={"id": "\d+"}))
* #Template()
*/
public function showAction($id)
{
$em = $this->getDoctrine()->getManager();
var_dump($id);
$entity = $em->getRepository('MyBackendBundle:Mountain')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Mountain entity.');
}
$deleteForm = $this->createDeleteForm($id);
return array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(),
);
}
it's works. But why he gets /login as a parameter?

Symfony2 - Sonata adminbundle menu won't show

.. What's up guys I've doing this project with Symfony 2.3.5 using FOSUSer Bundel and PUGXMultiUser Bundle and I wanted to use SonataAdmin Bundle but after configuration there was this problem about Menu that I could'nt see in the Dashboard .. Here is the configuration do you think I missed something !!
config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: #PokTVBundle/Resources/config/admin.yml }
framework:
#esi: ~
translator: { fallback: %locale% }
secret: %secret%
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_proxies: ~
session: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
# Assetic Configuration
assetic:
debug: %kernel.debug%
use_controller: false
bundles: [ ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: %kernel.root_dir%/Resources/java/compiler.jar
#yui_css:
# jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar
# Doctrine Configuration
doctrine:
dbal:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
charset: UTF8
# if using pdo_sqlite as your database driver, add the path in parameters.yml
# e.g. database_path: %kernel.root_dir%/data/data.db3
# path: %database_path%
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
spool: { type: memory }
#FOSBundle
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: POKEtudiant\UserBundle\Entity\User
service:
mailer: fos_user.mailer.twig_swift
user_manager: pugx_user_manager
#registration:
#confirmation:
#enabled: true
#from_email:
#address: noreply#POKEtudiant.com
#sender_name: Elamrani Abou Elassad
#PUGXBundle
pugx_multi_user:
users:
etudiants:
entity:
class: POKEtudiant\UserBundle\Entity\Etudiant
# factory:
registration:
form:
type: POKEtudiant\UserBundle\Form\Type\RegistrationEtudiantFormType
name: fos_user_registration_form
validation_groups: [etudiant_grp, Default]
template: UserBundle:Registration:etudiants.form.html.twig
profile:
form:
type: POKEtudiant\UserBundle\Form\Type\ProfileEtudiantFormType
name: fos_user_profile_form
#validation_groups: [Profile, Default]
recruteurs:
entity:
class: POKEtudiant\UserBundle\Entity\Recruiter
registration:
form:
type: POKEtudiant\UserBundle\Form\Type\RegistrationRecruiterFormType
template: UserBundle:Registration:recruteurs.form.html.twig
profile:
form:
type: POKEtudiant\UserBundle\Form\Type\ProfileRecruiterFormType
#SonataBlock
sonata_block:
default_contexts: [cms]
blocks:
sonata.admin.block.admin_list:
contexts: [admin]
#sonata.admin_doctrine_orm.block.audit:
# contexts: [admin]
sonata.block.service.text:
sonata.block.service.rss:
# Some specific block from the SonataMediaBundle
#sonata.media.block.media:
#sonata.media.block.gallery:
#sonata.media.block.feature_media:
#SonataKnp
knp_menu:
twig: # use "twig: false" to disable the Twig extension and the TwigRenderer
template: knp_menu.html.twig
templating: false # if true, enables the helper for PHP templates
default_renderer: twig # The renderer to use, list is also available by default
#SonataAdmin
sonata_admin:
title: PokTv
#title_logo: /bundles/acmedemo/fancy_acme_logo.png
#security:
#handler: sonata.admin.security.handler.noop
#acl_user_manager: fos_user.user_manager
templates:
# default global templates
layout: SonataAdminBundle::standard_layout.html.twig
ajax: SonataAdminBundle::ajax_layout.html.twig
dashboard: SonataAdminBundle:Core:dashboard.html.twig
# default actions templates, should extend a global templates
list: SonataAdminBundle:CRUD:list.html.twig
show: SonataAdminBundle:CRUD:show.html.twig
edit: SonataAdminBundle:CRUD:edit.html.twig
history: SonataAdminBundle:CRUD:history.html.twig
preview: SonataAdminBundle:CRUD:preview.html.twig
delete: SonataAdminBundle:CRUD:delete.html.twig
batch: SonataAdminBundle:CRUD:list__batch.html.twig
batch_confirmation: SonataAdminBundle:CRUD:batch_confirmation.html.twig
# list related templates
inner_list_row: SonataAdminBundle:CRUD:list_inner_row.html.twig
base_list_field: SonataAdminBundle:CRUD:base_list_field.html.twig
# default values of block templates, they should extend the base_block template
list_block: SonataAdminBundle:Block:block_admin_list.html.twig
dashboard:
blocks:
- { position: left, type: sonata.admin.block.admin_list }
# display two dashboard blocks
#-
#position: left
#type: sonata.admin.block.admin_list
#settings:
#groups: [Movies]
#-
#position: right
#type: sonata.admin.block.admin_list
#settings:
#groups: [Series]
groups:
Movies:
items:
- sonata.admin.movies
Series:
items:
- sonata.admin.series
Foot:
items:
- sonata.admin.foot
sonata_doctrine_orm_admin:
# default value is null, so doctrine uses the value defined in the configuration
entity_manager:
templates:
form:
- SonataDoctrineORMAdminBundle:Form:form_admin_fields.html.twig
filter:
- SonataDoctrineORMAdminBundle:Form:filter_admin_fields.html.twig
types:
list:
array: SonataAdminBundle:CRUD:list_array.html.twig
boolean: SonataAdminBundle:CRUD:list_boolean.html.twig
date: SonataAdminBundle:CRUD:list_date.html.twig
time: SonataAdminBundle:CRUD:list_time.html.twig
datetime: SonataAdminBundle:CRUD:list_datetime.html.twig
text: SonataAdminBundle:CRUD:base_list_field.html.twig
trans: SonataAdminBundle:CRUD:list_trans.html.twig
string: SonataAdminBundle:CRUD:base_list_field.html.twig
smallint: SonataAdminBundle:CRUD:base_list_field.html.twig
bigint: SonataAdminBundle:CRUD:base_list_field.html.twig
integer: SonataAdminBundle:CRUD:base_list_field.html.twig
decimal: SonataAdminBundle:CRUD:base_list_field.html.twig
identifier: SonataAdminBundle:CRUD:base_list_field.html.twig
show:
array: SonataAdminBundle:CRUD:show_array.html.twig
boolean: SonataAdminBundle:CRUD:show_boolean.html.twig
date: SonataAdminBundle:CRUD:show_date.html.twig
time: SonataAdminBundle:CRUD:show_time.html.twig
datetime: SonataAdminBundle:CRUD:show_datetime.html.twig
text: SonataAdminBundle:CRUD:base_show_field.html.twig
trans: SonataAdminBundle:CRUD:show_trans.html.twig
string: SonataAdminBundle:CRUD:base_show_field.html.twig
smallint: SonataAdminBundle:CRUD:base_show_field.html.twig
bigint: SonataAdminBundle:CRUD:base_show_field.html.twig
integer: SonataAdminBundle:CRUD:base_show_field.html.twig
decimal: SonataAdminBundle:CRUD:base_show_field.html.twig
admin.yml
services:
sonata.admin.movies:
class: POKEtudiant\PokTVBundle\Admin\MoviesAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Movies", label: "Movies", show_in_dashboard: "true" }
arguments:
- ~
- POKEtudiant\PokTVBundle\Entity\Movies
- ~
sonata.admin.series:
class: POKEtudiant\PokTVBundle\Admin\SeriesAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Series", label: "Series" }
arguments:
- ~
- POKEtudiant\PokTVBundle\Entity\Series
- ~
sonata.admin.foot:
class: POKEtudiant\PokTVBundle\Admin\FootAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Foot", label: "Foot" }
arguments:
- ~
- POKEtudiant\PokTVBundle\Entity\Foot
- ~
app/config/routing.yml
#PokTV Bundle
pok_tv:
resource: "#PokTVBundle/Resources/config/routing.yml"
prefix: /PokTV
#User Bundle
user:
resource: "#UserBundle/Resources/config/routing.yml"
prefix: /
#Sonata Admin
admin:
resource: '#SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
prefix: /admin
_sonata_admin:
resource: .
type: sonata_admin
prefix: /admin
appKernel (registerBundles)
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new FOS\UserBundle\FOSUserBundle(),
new PUGX\MultiUserBundle\PUGXMultiUserBundle(),
new Sonata\BlockBundle\SonataBlockBundle(),
new Sonata\jQueryBundle\SonatajQueryBundle(),
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
new Sonata\AdminBundle\SonataAdminBundle(),
new POKEtudiant\UserBundle\UserBundle(),
new POKEtudiant\PokTVBundle\PokTVBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Acme\DemoBundle\AcmeDemoBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
It's looks like you have not configured ROLE_SONATA_ADMIN for your user;
Or just map it in security.yml, like this
security:
role_hierarchy:
ROLE_ADMIN: [ROLE_USER, ROLE_SONATA_ADMIN]
After your user will have this role, the menu must be displayed;
Check your twig file to see which block is still being used. The sonata blocks section only has sonata.admin.block.admin_list which should be loaded with the defaults.
You can get error feedback by enabling filters:
[sorry this is my first resonse. How do you get the formatting to work?]
sonata_block:
default_contexts: [cms]
exception:
default:
filter: debug_only
renderer: throw
filters:
debug_only: sonata.block.exception.filter.debug_only
ignore_block_exception: sonata.block.exception.filter.ignore_block_exception
keep_all: sonata.block.exception.filter.keep_all
keep_none: sonata.block.exception.filter.keep_none
renderers:
inline: sonata.block.exception.renderer.inline
inline_debug: sonata.block.exception.renderer.inline_debug
throw: sonata.block.exception.renderer.throw
Then add this line directly under the admin block:
blocks:
sonata.admin.block.admin_list:
contexts: [admin]
exception: { filter: keep_all, renderer: inline }

SonataUserBundle User entity doesn't map changes

I want to make the email field optional. I read that i need to use #AttributeOverrides annotation.
My Application\Sonata\UserBundle\Entity\User class:
namespace Application\Sonata\UserBundle\Entity;
use Sonata\UserBundle\Entity\BaseUser as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
*
* #ORM\Entity
* #ORM\Table(name="gm_user")
* #AttributeOverrides({
* #ORM\AttributeOverride(name="email", column=#ORM\Column(nullable=true)),
* #ORM\AttributeOverride(name="emailCanonical", column=#ORM\Column(nullable=true, unique=false))
* })
*/
class User extends BaseUser
{
/**
* #var integer $id
*
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* Get id
*
* #return integer $id
*/
public function getId()
{
return $this->id;
}
}
My config.yml:
imports:
- { resource: parameters.yml }
- { resource: security.yml }
framework:
#esi: ~
translator: { fallback: %locale% }
secret: %secret%
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: %kernel.debug%
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_proxies: ~
session: ~
fragments: ~
# Twig Configuration
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
# Assetic Configuration
assetic:
debug: %kernel.debug%
use_controller: false
bundles: [ ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: %kernel.root_dir%/Resources/java/compiler.jar
#yui_css:
# jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar
# Doctrine Configuration
doctrine:
dbal:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
charset: UTF8
# if using pdo_sqlite as your database driver, add the path in parameters.yml
# e.g. database_path: %kernel.root_dir%/data/data.db3
path: %database_path%
types:
json: Sonata\Doctrine\Types\JsonType
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
spool: { type: memory }
# FOSUserBundle Configuration
fos_user:
db_driver: orm
firewall_name: main
user_class: Application\Sonata\UserBundle\Entity\User
group:
group_class: Application\Sonata\UserBundle\Entity\Group
profile: # Authentication Form
form:
type: fos_user_profile
handler: fos_user.profile.form.handler.default
name: fos_user_profile_form
validation_groups: [Authentication]
sonata_block:
default_contexts: [cms]
blocks:
sonata.admin.block.admin_list:
contexts: [admin]
#sonata.admin_doctrine_orm.block.audit:
# contexts: [admin]
sonata.block.service.text:
sonata.block.service.action:
sonata.block.service.rss:
# Some specific block from the SonataMediaBundle
#sonata.media.block.media:
#sonata.media.block.gallery:
#sonata.media.block.feature_media:
sonata_admin:
title: Admin Panel
title_logo: /bundles/sonataadmin/logo_title.png
templates:
# default global templates
layout: SonataAdminBundle::standard_layout.html.twig
ajax: SonataAdminBundle::ajax_layout.html.twig
# default actions templates, should extend a global templates
list: SonataAdminBundle:CRUD:list.html.twig
show: SonataAdminBundle:CRUD:show.html.twig
edit: SonataAdminBundle:CRUD:edit.html.twig
dashboard:
blocks:
# display a dashboard block
- { position: left, type: sonata.admin.block.admin_list }
groups:
sonata_doctrine_orm_admin:
# default value is null, so doctrine uses the value defined in the configuration
entity_manager: ~
templates:
form:
- SonataDoctrineORMAdminBundle:Form:form_admin_fields.html.twig
filter:
- SonataDoctrineORMAdminBundle:Form:filter_admin_fields.html.twig
types:
list:
array: SonataAdminBundle:CRUD:list_array.html.twig
boolean: SonataAdminBundle:CRUD:list_boolean.html.twig
date: SonataAdminBundle:CRUD:list_date.html.twig
time: SonataAdminBundle:CRUD:list_time.html.twig
datetime: SonataAdminBundle:CRUD:list_datetime.html.twig
text: SonataAdminBundle:CRUD:base_list_field.html.twig
trans: SonataAdminBundle:CRUD:list_trans.html.twig
string: SonataAdminBundle:CRUD:base_list_field.html.twig
smallint: SonataAdminBundle:CRUD:base_list_field.html.twig
bigint: SonataAdminBundle:CRUD:base_list_field.html.twig
integer: SonataAdminBundle:CRUD:base_list_field.html.twig
decimal: SonataAdminBundle:CRUD:base_list_field.html.twig
identifier: SonataAdminBundle:CRUD:base_list_field.html.twig
show:
array: SonataAdminBundle:CRUD:show_array.html.twig
boolean: SonataAdminBundle:CRUD:show_boolean.html.twig
date: SonataAdminBundle:CRUD:show_date.html.twig
time: SonataAdminBundle:CRUD:show_time.html.twig
datetime: SonataAdminBundle:CRUD:show_datetime.html.twig
text: SonataAdminBundle:CRUD:base_show_field.html.twig
trans: SonataAdminBundle:CRUD:show_trans.html.twig
string: SonataAdminBundle:CRUD:base_show_field.html.twig
smallint: SonataAdminBundle:CRUD:base_show_field.html.twig
bigint: SonataAdminBundle:CRUD:base_show_field.html.twig
integer: SonataAdminBundle:CRUD:base_show_field.html.twig
decimal: SonataAdminBundle:CRUD:base_show_field.html.twig
When I'm trying to change schema by php app/console doctrine:schema:update --force I get:
Nothing to update - your database is already in sync with the current entity metadata.
Problem solved!
Everything works after:
Deleting files under Application\Sonata\UserBundle\Resources\config\doctrine\ directory
Running php app/console doctrine:schema:update --force

Categories