My composer file:
"php": ">=5.3.3",
"symfony/symfony": "2.6.*",
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "~1.2",
"twig/extensions": "~1.0",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~3.0",
"sensio/framework-extra-bundle": "~3.0",
"incenteev/composer-parameter-handler": "~2.0",
"friendsofsymfony/user-bundle": "1.3.3",
"sonata-project/core-bundle": "2.3.*#dev",
"sonata-project/admin-bundle": "2.4.*#dev",
"sonata-project/doctrine-orm-admin-bundle" : "*",
"sonata-project/easy-extends-bundle": "2.1.*#dev",
"sonata-project/user-bundle": "~2.2",
"knplabs/knp-menu-bundle": "~1.1",
"hwi/oauth-bundle": "~0.4#dev",
"sonata-project/cache-bundle": "~2.2"
If I use "php app/console sonata:easy-extends:generate -d src/ SonataUserBundle" - command generate namespace "Application", all my Bundles in namespace "WPE"...
I want user bundle in my namespace.
User entity renamed to "WPE\UserBundle\Entity\User", login, admin all work, but
users list in sonata send error "Class Application\Sonata\UserBundle\Entity\User does not exist"
I find (Find in path... in IDE PhpStorm) "Application\Sonata\UserBundle" in cache files and sonata documentation.
How I can use my namespace "WPE"?
Rename Application\Sonata\UserBundle to your YourVendor\UserBundle\Entity\User.
Rename Application\Sonata\UserBundle... namespace to YourVendor\UserBundle\... in all files.
Remove new Application\Sonata\UserBundle\ApplicationSonataUserBundle() from Appkernel.php and add YourVendor\UserBundle() in AppKernel.php.
Change config:
sonata_user:
#security_acl: true # Uncomment for ACL support
manager_type: orm # can be orm or mongodb
class:
user: YourVendor\UserBundle\Entity\User
group: YourVendor\UserBundle\Entity\Group
fos_user:
db_driver: orm # can be orm or odm
firewall_name: main
user_class: YourVendor\UserBundle\Entity\User
#user_class: Application\Sonata\UserBundle\Entity\User
group:
group_class: YourVendor\UserBundle\Entity\Group
#group_class: Application\Sonata\UserBundle\Entity\Group
group_manager: sonata.user.orm.group_manager
service:
user_manager: sonata.user.orm.user_manager
If your are using orm mapping:
mappings:
YourVendorUserBundle: ~
#ApplicationSonataUserBundle: ~
A PRAGMATIC WAY TO SOLVE THIS ISSUE
The easiest way to solve this problem is to use global namespace inside your VB, the global namespace is the only namespace allowed Application\YourBundle\Entity.
So, inside your mapping definition or inside your VB code, you will use one final namespace: problem solved. How to achieve this:
Declare only SuperClass inside a VB, don’t use final entity,
Call your entity BaseXXXX and make it abstract, change the properties from private to protected,
The same goes for a repository,
Always use Application\YourBundle\Entity\XXXX inside your code.
Of course, you need to create for each VB bundle:
a valid structure inside the Application directory,
a valid entity mapping definition,
a model inside the entity folder.
The last part is quite inefficient without an efficient tool to generate for you this structure: EasyExtendsBundle to the rescue.
HOW TO MAKE YOUR BUNDLE EASY EXTENDABLE?
Mainly all you need is to follow instructions in previous paragraph:
Declare you entity/repository as described above,
Use your entity/repository as described above,
Before generation you also need “skeleton” file that will describe AB entity. Skeleton file can either xml or yml. For fully working example see SonataMediaBundle.
At last you can run:
php app/console sonata:easy-extends:generate YourVBBundleName
Note that the –dest option allows you to choose the target directory, such as src. Default destination is app/.
If you want to use :
php app/console sonata:easy-extends:generate YourVBBundleName
You can modify some SonataAdmin fiels , it's not the best way but that can help you to run at least the commande and generate your bundle:
1 - In Sonata\EasyExtendsBundle\Bundle\BundleMetadata (ligne 95) make change like this:
$this->extendedNamespace = sprintf('WPE\\%s\\%s', $this->vendor, $information[1]);
2 - In Sonata\EasyExtendsBundle\Command\GenerateCommand (ligne 67) :
'application_dir' => sprintf("%s/WPE", $dest)
3 - in Sonata\EasyExtendsBundle\Generator\BundleGenerator (ligne 70 ) :
$file = sprintf('%s/WPE%s.php', $bundleMetadata->getExtendedDirectory(), $bundleMetadata->getName());
4 - In sonata-project / Resources / skeleton / bundle / bundle.mustache :
class WPE{{ bundle }} extends Bundle
{
/.../
}
5 - In Sonata\UserBundle\DependencyInjection\SonataUserExtension (ligne 162/163):
$defaultConfig['class']['user'] = sprintf('WPE\\Sonata\\UserBundle\\%s\\User', $modelType);
$defaultConfig['class']['group'] = sprintf('WPE\\Sonata\\UserBundle\\%s\\Group', $modelType);
Then Run php app/console sonata:easy-extends:generate.
Other way you can copy the UserBundle under WPE and make your change :
In config.yml
Your name spaces
You entities
your service
and Your class admin
Related
I use PHP8, Symfony 5.2 and Doctrine 3.0 in my project,
But the PHP 8 attributes, allowed since Doctrine 2.9, doesn't seem to work.
use Doctrine\ORM\Mapping\Entity;
**
* #Entity(repositoryClass="App\Repository\MyClassRepository")
*/
class MyClass
{
works fine.
use Doctrine\ORM\Mapping\Entity;
#[Entity(repositoryClass: MyClassRepository::class)]
class MyClass
{
Return [critical] Uncaught PHP Exception Doctrine\ORM\Mapping\MappingException: "Class "App\Entity\MyClass" is not a valid entity or mapped super class." at .../vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php line 378
here is my composer.json :
"composer/package-versions-deprecated": "1.11.99.1",
"doctrine/doctrine-bundle": "^2.3",
"doctrine/doctrine-migrations-bundle": "^3.1",
"doctrine/orm": "^3.0",
"symfony/console": "5.2.*",
"symfony/dotenv": "5.2.*",
"symfony/flex": "^1.3.1",
"symfony/framework-bundle": "5.2.*",
"symfony/proxy-manager-bridge": "5.2.*",
"symfony/yaml": "5.2.*"
This is because of doctrine bundle configuration. If all entities within the bundle use attributes just switch the metadata driver from "annotation" to "attribute"
doctrine:
orm:
auto_generate_proxy_classes: true
entity_managers:
default:
...
mappings:
MyBundle:
type: attribute
If some entities within a bundles use attributes and some others annotations - than it is better either choose only one format for metadata or implement a custom metadata driver.
The solution is use a custom AnnotationDriver.
Sample fully works implementation: https://github.com/baraja-core/doctrine/blob/master/src/Orm/Mapping/AnnotationDriver.php
I am using doctrine/data-fixtures in dev environments and require it as follows:
composer.json:
"autoload": {
"psr-0": {
"": "src/",
"SymfonyStandard": "app/"
},
"classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
},
"require-dev": {
"symfony/maker-bundle": "^1.8",
"phpunit/phpunit": "^7.0",
"doctrine/data-fixtures": "dev-rfc1872 as v1.2.1",
"doctrine/doctrine-fixtures-bundle": "^3.0"
},
In my Symfony 3.4 application my data fixtures live in /src/AppBundle/DataFixtures/ORM/*.php.
When I run composer, which in turn runs a Symfony cache:clear I get the following error:
[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'"
command:
In DefinitionErrorExceptionPass.php line 37:
While discovering services from namespace "AppBundle\", an error was thrown
when processing the class "AppBundle\DataFixtures\ORM\LoadCourseData": "Cl
ass Doctrine\Common\DataFixtures\AbstractFixture not found".
I would like to exclude the DataFixtures namespace from being autoloaded but I cannot find a way to do that.
I think you don't want to exclude data fixtures from being autoloaded, because they are valid PHP classes.
This error comes from Symfony's autowiring feature. So I assume you're indeed using autowiring.
You should data fixtures from autowiring discovery, which can be done in services.yml with exclude option.
Assuming you have something like (which should be there by default):
AppBundle\:
resource: '../../src/AppBundle/*'
exclude: '../../src/AppBundle/{Entity,Repository}'
All you need to do is to add DataFixtures namespace to exclude:
AppBundle\:
resource: '../../src/AppBundle/*'
exclude: '../../src/AppBundle/{Entity,Repository,DataFixtures}'
You can read more about it in here nad here
I'm using Symfony framework and SonataBundle to build the admin application.
When I'm trying to setup a field with type blob and using the "sonata_simple_formatter_type" of SonataFormatterBundle, i was got the error:
Could not load type "sonata_simple_formatter_type"
Here is my composer.json file:
"symfony/symfony": "2.8.*",
"doctrine/orm": "^2.4.8",
//*...*/
"sonata-project/admin-bundle": "2.3.10",
"sonata-project/doctrine-orm-admin-bundle": "2.3.3",
"sonata-project/user-bundle": "2.2.4",
"sonata-project/formatter-bundle": "2.3.3",
I was prefer to this link to making the admin app: sonata formatter
To fix the error, you also need to configure SonataFormatterBundle: https://sonata-project.org/bundles/formatter/master/doc/reference/installation.html
For the SonataAdminBundle you also need to do some extra configuration: https://sonata-project.org/bundles/formatter/master/doc/reference/formatter_widget.html#sonata-admin-integration
I've configured SonataUserBundle together with SonataAdminBundle. I now have access to URLs like /login, /register, /profile. This is how the login page looks like. Other pages also do not have any styles loaded.
Does Sonata provide any default styles for these pages. I though that maybe I have a problem with dependency version. This is 'Sonata' fragment of my composer.json:
"sonata-project/admin-bundle": "~2.3",
"sonata-project/doctrine-orm-admin-bundle": "^2.3",
"sonata-project/easy-extends-bundle": "^2.1",
"sonata-project/user-bundle": "^2.2",
"knplabs/knp-menu": "~1.1",
"knplabs/knp-menu-bundle": "~1.1",
"sonata-project/core-bundle": "~2.3"
I've also installed the assets with php app/console assets:install web --symlink, cleared the cache with php app/console cache:clear.
When I inspect the 'Network' tab in the Chrome Dev tools, no asset files are ever attempted to be loaded.
I'd rather expect something like this.
What am I missing here?
You shall check first in your configuration with the reference one on the official documentation :
https://sonata-project.org/bundles/admin/master/doc/reference/configuration.html
for the 2.3 version, you should have :
assets:
stylesheets:
# Defaults:
- bundles/sonataadmin/vendor/bootstrap/dist/css/bootstrap.min.css
- bundles/sonataadmin/vendor/AdminLTE/css/font-awesome.min.css
- bundles/sonataadmin/vendor/AdminLTE/css/ionicons.min.css
- bundles/sonataadmin/vendor/AdminLTE/css/AdminLTE.css
- bundles/sonatacore/vendor/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css
- bundles/sonataadmin/vendor/jqueryui/themes/base/jquery-ui.css
- bundles/sonataadmin/vendor/select2/select2.css
- bundles/sonataadmin/vendor/select2/select2-bootstrap.css
- bundles/sonataadmin/vendor/x-editable/dist/bootstrap3-editable/css/bootstrap-editable.css
- bundles/sonataadmin/css/styles.css
- bundles/sonataadmin/css/layout.css
javascripts:
# Defaults:
- bundles/sonataadmin/vendor/jquery/dist/jquery.min.js
- bundles/sonataadmin/vendor/jquery.scrollTo/jquery.scrollTo.min.js
- bundles/sonatacore/vendor/moment/min/moment.min.js
- bundles/sonataadmin/vendor/bootstrap/dist/js/bootstrap.min.js
- bundles/sonatacore/vendor/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js
- bundles/sonataadmin/vendor/jqueryui/ui/minified/jquery-ui.min.js
- bundles/sonataadmin/vendor/jqueryui/ui/minified/i18n/jquery-ui-i18n.min.js
- bundles/sonataadmin/jquery/jquery.form.js
- bundles/sonataadmin/jquery/jquery.confirmExit.js
- bundles/sonataadmin/vendor/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.min.js
- bundles/sonataadmin/vendor/select2/select2.min.js
- bundles/sonataadmin/App.js
- bundles/sonataadmin/Admin.js
I come here with this weird issue around Symfony2 translations since I don't know what else to do. As title says "translations works if a user is logged in, otherwise doesn't. Here is what I've done:
Set default locale and translator at config.yml:
framework:
translator: { fallback: "%locale%" }
default_locale: "%locale%"
Set locale value at parameters.yml
locale: es
Set language at base template:
<html lang="{{ app.request.locale }}">
Check locale after page loads in Twig template where issue is happening:
{{ app.request.locale }} // returns "es" it's right
Clear the cache several/many/manyyyyyyyyyyy times:
1st approach (didn't work):
php app/console cache:clear
php app/console cache:warmup
2nd approach (didn't work):
rm -rf /app/cache
3th approach (didn't work): cd to app/cache and select each file one by one (using mc from Linux) and remove all them including directories by pressing F8
Clear browser cache and test in Firefox/Chrome
I've checked the app/cache dir under translations directory and there is a file catalogue.es.php which contains all the translated strings so translation is working.
My translation are defined in a messages.es.yml file at AppBundle/Resources/translations and this is an example of the content:
registro:
natural:
panelTitulo: Datos del Usuario
columnas:
tipo_usuario: Tipo de Usuario
campos:
tipoTramite: Tipo de Trámite
Then in my view this is how I access those translations:
{{'registro.natural.panelTitulo'|trans}}
{{'registro.columnas.tipo_usuario'|trans}}
But this, when user is not logged in, does not work, but, if I logged in and try this translation instead:
{{'campos.tipoTramite'|trans}}
{{ 'registro.columnas.tipo_usuario'|trans }}
and both works (I'm using FOSUserBundle for User management but translations doesn't belongs to any domain, just in the directory I mention earlier) so I'm complete lost since I don't know what else to do. Can any give me some advice around this? Translation only work if user has logged in in a application? I'm doing something wrong? How is that possible?
Extra information
This is the relevant part of my composer.json file those are the bundles I'm using on my application right now, any one problematic?
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.5.*",
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "~1.2",
"twig/extensions": "~1.0",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~3.0",
"sensio/framework-extra-bundle": "3.0.*#dev",
"friendsofsymfony/user-bundle": "~2.0#dev",
"friendsofsymfony/jsrouting-bundle": "2.0.*#dev",
"friendsofsymfony/rest-bundle": "1.5.*#dev",
"jms/serializer-bundle": "0.13.*#dev",
"jms/di-extra-bundle": "1.4.*#dev",
"jms/security-extra-bundle": "dev-master",
"knplabs/knp-paginator-bundle": "2.4.*#dev",
"knplabs/knp-menu": "2.0.*#dev",
"knplabs/knp-menu-bundle": "2.0.*#dev",
"stof/doctrine-extensions-bundle": "1.2.*#dev",
"misd/phone-number-bundle": "~1.0",
"raulfraile/ladybug-bundle": "~1.0",
"h4cc/alice-fixtures-bundle": "dev-master",
"oneup/uploader-bundle": "dev-master",
"willdurand/js-translation-bundle": "2.1.*#dev",
"vich/uploader-bundle": "1.0.*#dev"
}
messages is a fairly common keyword for a translation domain and I suspect that conflicting bundles are overriding your translation file in certain scenarios. To fix this:
Rename your messages.es.yml file to AppBundle.es.yml
Use this format {{ 'registro.natural.panelTitulo'|trans({}, 'AppBundle') }} for all usage of your bundle translations, especially when working with Twig files outside of AppBundle
Clear your caches