Installation EasyAdmin on Symfony4 - symfony

I try to install EasyAdminBundle on fresh install of Symfony4 from this doc https://symfony.com/doc/current/bundles/EasyAdminBundle/index.html
But I can't access to the back-end, I'm getting 404...
I just type composer require easycorp/easyadmin-bundle, and add my entity(Command) to framework.yaml
framework:
secret: '%env(APP_SECRET)%'
#default_locale: en
#csrf_protection: true
#http_method_override: true
# Enables session support. Note that the session will ONLY be started if you read or write from it.
# Remove or comment this section to explicitly disable session support.
session:
handler_id: ~
#esi: true
#fragments: true
php_errors:
log: true
cache:
# Put the unique name of your app here: the prefix seed
# is used to compute stable namespaces for cache keys.
#prefix_seed: your_vendor_name/app_name
# The app cache caches to the filesystem by default.
# Other options include:
# Redis
#app: cache.adapter.redis
#default_redis_provider: redis://localhost
# APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
#app: cache.adapter.apcu
easy_admin:
entities:
# change the following to the namespaces of your own entities
- App\Entity\Command
When I check my routes with php bin/console debug:router
-------------------------- -------- -------- ------ -----------------------------------
Name Method Scheme Host Path
-------------------------- -------- -------- ------ -----------------------------------
easyadmin ANY ANY ANY /admin/
admin ANY ANY ANY /admin/
_twig_error_test ANY ANY ANY /_error/{code}.{_format}
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler_open_file ANY ANY ANY /_profiler/open
_profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
-------------------------- -------- -------- ------ -----------------------------------
Could some one enlighten me ?
Be wrong on the first line of configuration is so frustrating...

Maybe it help someone. I have same problem in symfony 4, check your /public directory, if missed .htaccess install composer require symfony/apache-pack and try again /admin
https://symfony.com/doc/current/setup/web_server_configuration.html

Well, I've installed without problem easy-admin in one SF4 proyect. Try those steps:
In config/routes/easy_admin.yaml:
easy_admin_bundle:
resource: '#EasyAdminBundle/Controller/AdminController.php'
prefix: /admin
type: annotation
In config/packages/easy_admin.yaml write (and delete it from framework.yaml):
easy_admin:
entities:
- App\Entity\Command
When you install easy-admin you must have this line in your bundles.php file:
EasyCorp\Bundle\EasyAdminBundle\EasyAdminBundle::class => ['all' => true],
On the other hand you have some yaml syntax error in your framework.yaml file.

Related

Issue while setting mailer in pimcore(symfony) :- Invalid configuration for path "framework.mailer": "dsn" and "transports" cannot be used together

Facing an issue with the mailer in pimcore 10.2 is made in symfony5.4.
Invalid configuration for path "framework.mailer": "dsn" and "transports" cannot be used together.
The setting I have done for the mail
# .env
MAILER_DSN=smtp://user:pass#smtp.example.com:port
# config/packages/mailer.yaml
framework:
mailer:
dsn: '%env(MAILER_DSN)%'
I didn't set any other mail transport.
#### SYMFONY MAILER TRANSPORTS
# mailer:
# transports:
# main: smtp://user:pass#smtp.example.com:port
# pimcore_newsletter: smtp://user:pass#smtp.example.com:port
Error gone when I remove mailer.yaml file. But then mail is not sending.
The problem was in mailer.yaml.
It should be like
# config/packages/mailer.yaml
framework:
mailer:
transports:
main: '%env(MAILER_DSN)%'

Symfony with buggy routing on apache

I installed Symfony on a fresh Debian 9 server.
I created a project:
composer create-project symfony/website-skeleton symfony
(masch3 is the name of my development machine)
When opening http://masch3/symfony/public/
I get the well known Symfony welcome page.
When I create the most simple Controller named "home"
class HomeController extends AbstractController
{
#[Route('/home', name: 'home')]
public function index(): Response
{
return $this->render('home/index.html.twig', [
'controller_name' => 'HomeController',
]);
}
}
http://masch3/symfony/public/home -> 404 not found
http://masch3/symfony/public/index.php/home -> OK
As recommended in other answers, I installed Apache pack with
composer require symfony/apache-pack
But this still does not do.
php bin/console debug:router
-------------------------- -------- -------- ------ -----------------------------------
Name Method Scheme Host Path
-------------------------- -------- -------- ------ -----------------------------------
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler_open_file ANY ANY ANY /_profiler/open
_profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
_preview_error ANY ANY ANY /_error/{code}.{_format}
home ANY ANY ANY /home
-------------------------- -------- -------- ------ -----------------------------------
php bin/console about
-------------------- -------------------------------------------
Symfony
-------------------- -------------------------------------------
Version 6.0.2
Long-Term Support No
End of maintenance 07/2022 (in +194 days)
End of life 07/2022 (in +194 days)
-------------------- -------------------------------------------
Kernel
-------------------- -------------------------------------------
Type App\Kernel
Environment dev
Debug true
Charset UTF-8
Cache directory ./var/cache/dev (6.8 MiB)
Build directory ./var/cache/dev (6.8 MiB)
Log directory ./var/log (19 KiB)
-------------------- -------------------------------------------
PHP
-------------------- -------------------------------------------
Version 8.0.14
Architecture 64 bits
Intl locale de_DE
Timezone Europe/Berlin (2022-01-18T13:45:22+01:00)
OPcache true
APCu false
Xdebug false
-------------------- -------------------------------------------
Edit the main Apache config file:
sudo nano /etc/apache2/apache2.conf
look for this section:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Replace AllowOverride None with AllowOverride All
Activate apache’s rewrite module.
sudo a2enmod rewrite
sudo systemctl restart apache2
Go to your Symfony project's folder and install Apache pack
cd /var/www/html/symfony
composer require symfony/apache-pack
Now:
http://masch3/symfony/public/home -> ok

Symfony: The class XYZ was not found in the chain configured namespaces

Existing questions did not help.
I am still learning Symfony and setting up an existing project. Trying to run doctrine fixtures from my application directory.
./app/console doctrine:fixtures:load --env test
And running this gives me following errors
Error thrown while running command "doctrine:fixtures:load --env test --em default". Message: "The class 'ClientPortal\GenericBundle\Document\Accountant' was not found in the chain configured namespaces _XyzProjectName\CalendarContext\Domain\Model, Integration\GetFeedbackBundle\Model, _XyzProjectName\AccountingProcessContext\Domain\Model, _XyzProjectName\CaseContext\Domain" {"exception":"[object] (Doctrine\Common\Persistence\Mapping\MappingException(code: 0): The class 'ClientPortal\GenericBundle\Document\Accountant' was not found in the chain configured namespaces _XyzProjectName\CalendarContext\Domain\Model, Integration\GetFeedbackBundle\Model, _XyzProjectName\AccountingProcessContext\Domain\Model, _XyzProjectName\CaseContext\Domain at /usr/local/var/www/1800-api/vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/Mapping/MappingException.php:22)
And this exception is being thrown when trying to persist object of class
'ClientPortal\GenericBundle\Document\Accountant'
and here is my doctrine in config.yml
doctrine:
dbal:
driver: pdo_pgsql
host: '%database_host%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
mappings:
CalendarBundle:
prefix: '_XyzProjectName\CalendarContext\Domain\Model'
IntegrationGetFeedbackBundle:
prefix: 'Integration\GetFeedbackBundle\Model'
AccountingProcessBundle:
prefix: '_XyzProjectName\AccountingProcessContext\Domain\Model'
CaseBundle:
prefix: '_XyzProjectName\CaseContext\Domain'
GenericBundle:
type: "annotation"
prefix: 'ClientPortal\GenericBundle\Document'
dir: 'src'
is_bundle: false
The snippet which is raising this exception
$account = new ClientPortal\GenericBundle\Document\Accountant();//full namespace added for clarity - also this file lies in the same directory structure.
$account->setSfAccountantId($accountantId);
$account->setUsername($username);
$manager = new ObjectManager;
$manager->persist( $account ); //This throws the above mentioned exception
My thought is, the file ClientPortal\GenericBundle\Document\Accountant.php is being autoloaded as there is no exception thrown at the time of instantion of its object. But, there is something missing with configuration or mapping because of which doctrine does not know how to persist its object.
[Source code][1] Accountant class
GenericBundle(s) registered under AppKernel
new Website\GenericBundle\WebsiteGenericBundle(),
new Admin\GenericBundle\AdminGenericBundle(),
new ClientPortal\GenericBundle\ClientPortalGenericBundle(),
new TaxApp\GenericBundle\TaxAppGenericBundle(),
So, as I suggested in comments - try to add ClientPortal\GenericBundle\Document\ namespace to mappings in your doctrine config file, like that:
#...
orm:
auto_generate_proxy_classes: "%kernel.debug%"
mappings:
# ...
ClientPortalGenericBundle:
type: annotation
prefix: 'ClientPortal\GenericBundle\Document\'
dir: '%kernel.root_dir%/src/ClientPortal/GenericBundle/Document/'
#is_bundle: false
auto_mapping: true
Had the same issue with Symfony 4 while using multiple database connections. This one https://stackoverflow.com/a/55361742/2540699 helped me to solved my problem.
I bumped into this kind of message in my Symfony 6.1 project, using multiple entity managers, with one of the entity managers specified as default in doctrine.yaml:
doctrine:
orm:
default_entity_manager: general
entity_managers:
general:
# config for general
other_entity_manager:
# config for other entity manager
Everything was fine on my dev environment, but on production I got the error
Uncaught PHP Exception Doctrine\Persistence\Mapping\MappingException: "The class XXX was not found in the chain configured namespaces " at /opt/approot/current/vendor/doctrine/persistence/src/Persistence/Mapping/MappingException.php
Problem seemed to be that I have a when#prod: section in my doctrine.config.yml. It seems I had to repeat the default_entity_manager over there:
when#prod:
doctrine:
orm:
default_entity_manager: general
# other prod-specific configuration
This fixed it for me.
Update: This is probably related to this issue: https://github.com/symfony/symfony/issues/27769

Empty dashboard for not ROLE_SUPER_ADMIN user (symfony2, sonata acl)

I use ACL in Sonata Admin Bundle. Аnd when I log in as a root (which has ROLE_SUPER_ADMIN) I can create new users. I've created one (named qwer) and then loged in as qwer.
PROBLEM: in my situation qwer user has empty dashbord, even having roles like
ROLE_SONATA_USER_ADMIN_USER_GUEST, ROLE_SONATA_USER_ADMIN_USER_STAFF, ROLE_SONATA_USER_ADMIN_USER_EDITOR
Please tell my -- what should I do to understad where the problem is.
Did you follow the documentation for ACL fully? You should add your sonata_admin configuration and security.yml just to be sure. Mine looks like:
sonata_admin:
# ...
security:
handler: sonata.admin.security.handler.acl
# acl security information
information:
LIST: [LIST]
GUEST: [VIEW, LIST]
STAFF: [LIST, CREATE]
EDITOR: [OPERATOR, EXPORT, EDIT]
ADMIN: [MASTER]
admin_permissions: [CREATE, LIST, DELETE, UNDELETE, EXPORT, OPERATOR, MASTER]
# permission related to the objects
object_permissions: [VIEW, EDIT, DELETE, UNDELETE, OPERATOR, MASTER, OWNER]
Also ensure your security.yml has the required configuration:
security:
# ...
providers:
fos_userbundle:
id: fos_user.user_manager
acl:
connection: default
access_decision_manager:
strategy: unanimous
And add a PermissionMap to your app/config/parameters.yml or bundle parameters:
# src/AppBundle/Resources/config/services.yml
parameters:
# ...
# Symfony 3 and above
security.acl.permission.map:
class: Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap
# Symfony < 3
security.acl.permission.map.class: Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap
Then there are 3 commands you will need to run:
Initialize your ACL setup (only once)
php app/console init:acl
Reload changes to the configuration (every change in the sonata_admin configuration file)
php app/console sonata:admin:setup-acl
To generate (new) ACL rules for already existing entities/objects. (every change in the sonata_admin configuration file)
php app/console sonata:admin:generate-object-acl
Then once the configuration is setup, logout and log back in again for the roles to apply.
to resolve this problem check that your have in of your app bundle lines:
services:
security.acl.permission.map:
class: Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap
parameters:

Sonata Page Bundle - creating a page

I'm trying to use Sonata Page Bundle and I've installed it without any issues but I'm having trouble adding blocks to pages. When I looked at Sonata Sandbox I can create page and when I click View Page it will generate blocks automatically which it doesn't do in my project.
I have basically copied settings from sonata sandbox. Also in sanbox if I'm logged in I can access the page without creating publication which in my project I'm getting an error route not found.
cmf_routing:
chain:
routers_by_id:
# enable the DynamicRouter with high priority to allow overwriting configured routes with content
#symfony_cmf_routing_extra.dynamic_router: 200
# enable the symfony default router with a lower priority
sonata.page.router: 150
router.default: 100
sonata_page:
multisite: host # host_with_path
use_streamed_response: false # set the value to false in debug mode or if the reverse proxy does not handle streamed response
ignore_route_patterns:
- (.*)admin(.*) # ignore admin route, ie route containing 'admin'
- ^_(.*) # ignore symfony routes
ignore_routes:
- sonata_page_cache_esi
- sonata_page_cache_ssi
- sonata_page_js_sync_cache
- sonata_page_js_async_cache
- sonata_cache_esi
- sonata_cache_ssi
- sonata_cache_js_async
- sonata_cache_js_sync
- sonata_cache_apc
ignore_uri_patterns:
- admin(.*) # ignore admin route, ie route containing 'admin'
cache_invalidation:
service: sonata.page.cache.invalidation.simple
recorder: sonata.page.cache.recorder
classes:
"Application\Sonata\PageBundle\Entity\Block": getId
default_template: default
templates:
default: { path: 'SonataPageBundle::layout.html.twig', name: 'default' }
2col: { path: 'SonataPageBundle::2columns_layout.html.twig', name: '2 column' }
page_defaults:
homepage: {decorate: false, enabled: true}
#caches:
# esi:
# token: add an unique token here # default is a random value
# version: 3 # version 3 is the default on debian wheezy ...
# servers:
# # you need to ajust this configuration to match your varnish configuration
# - %sonata_page.varnish.command%
# ssi:
# token: add an unique token here # default is a random value
catch_exceptions:
not_found: [404] # render 404 page with "not_found" key (name generated: _page_internal_error_{key})
fatal: [500] # so you can use the same page for different http errors or specify specific page for each error
# Enable Doctrine to map the provided entities
doctrine:
orm:
entity_managers:
default:
mappings:
ApplicationSonataPageBundle: ~
SonataPageBundle: ~
Thanks for any advice
1 - You are right, from front-end site, being logged-in, creating page and then clicking on View Page will generate blocks automatically. This is awesome, but unfortunately the feature will be deleted in futur versions (explanations included)
To use it for now, read the Full configuration options
sonata_page:
(...)
is_inline_edition_on: true
2 - No idea. To perform a global publication, just in case:
php app/console sonata:page:update-core-routes --site=all
php app/console sonata:page:create-snapshots --site=all

Resources