I have two bundle main AppBundle and PrestaShopConnectionBundle to get information from PrestaShop datebase.
When I'm trying to get information from ProductShop entity I got error:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'prestashop.ps_product_shop' doesn't exist
command
php app/console doctrine:schema:update --dump-sql --em=prestashop
return "Nothing to update" so it is probably detected table from PrestaShop.
But why controller can't get date from it?
<?php
//src/PrestaShopConnectionBundle/Entity/ProductShop.php
namespace PrestaShopConnectionBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="prestashop.ps_product_shop")
*/
class ProductShop
{
/**
* #ORM\Column(type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
* #ORM\Column(name="id_product")
*/
protected $id;
/**
* #ORM\Column(type="decimal", precision=20, scale=6, name="price")
* #ORM\Column()
*/
protected $price;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set price
*
* #param string $price
* #return ProductShop
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* Get price
*
* #return string
*/
public function getPrice()
{
return $this->price;
}
}
<?php
//src/PrestaShopConnectionBundle/Entity/ProductShop.php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use PrestaShopConnectionBundle\Entity\ProductShop;
class DefaultController extends Controller
{
/**
* #Route("/app/example", name="homepage")
*/
public function indexAction()
{
$product = $this->get('doctrine')
->getRepository('PrestaShopConnectionBundle:ProductShop', 'prestashop')
->findAll();
dump($product);
return $this->render('default/index.html.twig');
}
}
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
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
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']
#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%"
# 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"
less:
node: /usr/bin/node
node_paths: [/usr/lib/node_modules]
# Doctrine Configuration
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
prestashop:
driver: pdo_mysql
host: "%database_shop_host%"
port: "%database_shop_port%"
dbname: "%database_shop_name%"
user: "%database_shop_user%"
password: "%database_shop_password%"
charset: UTF8
mapping_types:
enum: string
orm:
default_entity_manager: default
auto_generate_proxy_classes: "%kernel.debug%"
entity_managers:
default:
connection: default
naming_strategy: doctrine.orm.naming_strategy.underscore
mappings:
AppBundle: ~
PrestaShopConnectionBundle: ~
prestashop:
connection: prestashop
naming_strategy: doctrine.orm.naming_strategy.underscore
mappings:
PrestaShopConnectionBundle: ~
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
mopa_bootstrap:
form:
show_legend: false # default is true
show_child_legend: false # default is true
error_type: block # or inline which is default
As #OIS noted, #ORM\Table(name="prestashop.ps_product_shop") is bad!
I just copied from my application so it should work fine if you can adopt into yours.
parameters.yml
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: ~
database_name: abc_dev
database_user: dev
database_password: mysqlpassword
database_path: ~
def_database_driver: pdo_mysql
def_database_host: 127.0.0.1
def_database_port: ~
def_database_name: def_dev
def_database_user: dev
def_database_password: mysqlpassword
def_database_path: ~
config.yml
doctrine:
dbal:
default_connection: abc
connections:
abc:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
charset: UTF8
mapping_types:
enum: string
def:
driver: %def_database_driver%
host: %def_database_host%
port: %def_database_port%
dbname: %def_database_name%
user: %def_database_user%
password: %def_database_password%
charset: UTF8
mapping_types:
enum: string
orm:
auto_generate_proxy_classes: %kernel.debug%
default_entity_manager: abc
entity_managers:
abc:
connection: abc
mappings:
ApplicationAbcBundle:
dir: Entity/Abc
def:
connection: def
mappings:
ApplicationDefBundle:
dir: Entity/Def
application structure
src
Application
AbcBundle
Entity
Abc
your entities....
DefBundle
Entity
Def
your entities....
Example command lines
app/console doctrine:schema:update --em:abc --force
app/console doctrine:generate:entities ...... --em:def
Related
**Security.yml** Creating Authentication (Log in page)
I have attached a error screen shot i am unable to view the page.
Security.yml Creating Authentication (Log in page)
I have attached a error screen shot i am unable to view the page.
Security.yml Creating Authentication (Log in page)
I have attached a error screen shot i am unable to view the page.
Security.yml Creating Authentication (Log in page)
I have attached a error screen shot i am unable to view the page.
[![enter image description here][1]][1]
# To get started with security, check out the documentation:
# https://symfony.com/doc/current/security.html
security:
encoders:
AppBundle\Entity\User:
algorithm: bcrypt
# https://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
providers:
db_provider:
entity:
class: AppBundle:User
property: username
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: ~
form_login:
login_path: login
check_path: login
**User.php** This is my entity
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* #ORM\Table(name="user")
* #ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
*/
class User implements UserInterface, \Serializable
{
/**
* #ORM\Column(type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(type="string", length=25, unique=true)
*/
private $username;
/**
* #ORM\Column(type="string", length=64)
*/
private $password;
/**
* #ORM\Column(type="string", length=60, unique=true)
*/
private $email;
/**
* #ORM\Column(name="is_active", type="boolean")
*/
private $isActive;
public function __construct()
{
$this->isActive = true;
// may not be needed, see section on salt below
// $this->salt = md5(uniqid('', true));
}
public function getUsername()
{
return $this->username;
}
public function getSalt()
{
// you *may* need a real salt depending on your encoder
// see section on salt below
return null;
}
public function getPassword()
{
return $this->password;
}
public function getRoles()
{
return array('ROLE_USER');
}
public function eraseCredentials()
{
}
/** #see \Serializable::serialize() */
public function serialize()
{
return serialize(array(
$this->id,
$this->username,
$this->password,
// see section on salt below
// $this->salt,
));
}
/** #see \Serializable::unserialize() */
public function unserialize($serialized)
{
list (
$this->id,
$this->username,
$this->password,
// see section on salt below
// $this->salt
) = unserialize($serialized);
}
}
[1]: https://i.stack.imgur.com/U1IJX.jpg
**config.yml**
This is my config.yml here i added driver pdo_sqlite and form_theme: -'bootstrap_3_layout.html.twig'
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%'
form_theme:
- 'bootstrap_3_layout.html.twig'
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_sqlite
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
charset: UTF8
path: '% database_path %'
# 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%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }
**parameters.yml**
This is my parameters.yml file i didn't change anything in this file.
# This file is auto-generated during the composer install
parameters:
database_host: 127.0.0.1
database_port: null
database_name: symfony
database_user: root
database_password: null
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
secret: ab2af876f87b559feb166e695a29ec552758419a
**parameters.yml.dist**
This is my **parameters.yml.dist** here i uncomment database_path:
This is my **parameters.yml.dist** here i uncomment database_path:
This is my **parameters.yml.dist** here i uncomment database_path:
This is my **parameters.yml.dist** here i uncomment database_path:
# This file is a "template" of what your parameters.yml file should look like
# Set parameters here that may be different on each deployment target of the app, e.g. development, staging, production.
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
parameters:
database_host: 127.0.0.1
database_port: ~
database_name: symfony
database_user: root
database_password: ~
# You should uncomment this if you want to use pdo_sqlite
database_path: '%kernel.project_dir%/var/data/data.sqlite'
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: ~
mailer_password: ~
# A secret key that's used to generate certain security-related tokens
secret: ThisTokenIsNotSoSecretChangeIt
Your configuration/indentation is wrong.
Change
providers:
db_provider:
entity:
class: AppBundle:User
property: username
To
providers:
db_provider:
entity:
class: AppBundle:User
property: username
Reference: http://symfony.com/doc/current/reference/configuration/security.html
I want to add a profile picture to my admin class, but i got this error :
Attempted to load class "Media" from namespace "Application\MediaBundle\Entity".
Did you forget a "use" statement for e.g. "Sonata\MediaBundle\Model\Media", "Sonata\MediaBundle\Tests\Entity\Media", "Sonata\MediaBundle\Tests\Document\Media" or "Sonata\MediaBundle\Tests\PHPCR\Media"?
I searched a lot but no solution.
this is my code
user entity
> /**
> * #var \Application\Sonata\MediaBundle\Entity\Media
> * #ORM\ManyToOne(targetEntity="Application\Sonata\MediaBundle\Entity\Media",
> cascade={"persist"}, fetch="LAZY")
> */
> protected $media;
>
> /**
> * Set media
> *
> * #param \Application\Sonata\MediaBundle\Entity\Media $media
> * #return User
> */
> public function setMedia(\Application\Sonata\MediaBundle\Entity\Media $media = null)
> {
> $this->media = $media;
>
> return $this;
> }
>
> /**
> * Get media
> *
> * #return \Application\Sonata\MediaBundle\Entity\Media
> */
> public function getMedia()
> {
> return $this->media;
> }
user admin
/**
* #param \Sonata\AdminBundle\Form\FormMapper $formMapper
*
* #return void
*/
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('General')
->add('username')
->add('email')
->add('enabled')
->add('firstname')
->add('lastname')
->add('plainPassword', 'password', array(
'required' => (!$this->getSubject() || is_null($this->getSubject()->getId())),
))
->add('media', 'sonata_media_type', array('provider' => 'sonata.media.provider.image', 'context' => 'engine', 'data_class' => 'Application\Sonata\MediaBundle\Entity\Media', 'required' => false))
->end();
}
config.yml
# app/config/config.yml
sonata_media:
class:
media: Application\MediaBundle\Entity\Media
gallery: Application\MediaBundle\Entity\Gallery
gallery_has_media: Application\MediaBundle\Entity\GalleryHasMedia
# 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
db_driver: doctrine_orm # or doctrine_mongodb, doctrine_phpcr it is mandatory to choose one here
default_context: default # you need to set a context
contexts:
default: # the default context is mandatory
providers:
- sonata.media.provider.dailymotion
- sonata.media.provider.youtube
- sonata.media.provider.image
- sonata.media.provider.file
- sonata.media.provider.vimeo
formats:
small: { width: 100 , quality: 70}
big: { width: 500 , quality: 70}
# other contexts here
engine:
providers:
- sonata.media.provider.image
formats:
preview: { width: 100, quality: 100}
small: { width: 200, quality: 100}
large: { width: 600, quality: 100}
cdn:
server:
path: /uploads/media # http://media.sonata-project.org/
filesystem:
local:
directory: "%kernel.root_dir%/../web/uploads/media"
create: false
providers:
image:
resizer: sonata.media.resizer.square
doctrine:
orm:
entity_managers:
default:
mappings:
FOSUserBundle: ~
SonataMediaBundle: ~
dbal:
types: #this is about this line and line below
json: \Doctrine\DBAL\Types\StringType
doctrine_phpcr:
odm:
auto_mapping: true
mappings:
SonataMediaBundle:
prefix: Sonata\MediaBundle\PHPCR
this is the tutoruial
any help ?
sorry for the english
the problem is in the configuration file config.yml
> sonata_media:
> class:
> media: Application\Sonata\MediaBundle\Entity\Media
> gallery: Application\Sonata\MediaBundle\Entity\Gallery
> gallery_has_media: Application\Sonata\MediaBundle\Entity\GalleryHasMedia
> category: Application\Sonata\ClassificationBundle\Entity\Category
I have this Error when i'm trying to access my site with a fresh installation of sonata adminBUndle. I can see the list i can see the dashboard but if i try to add a post I got this message.
Missing argument 1 for Sonata\AdminBundle\Admin\Admin::__construct(),
called in
C:\wamp\www\sonata\vendor\sonata-project\doctrine-orm-admin-bundle\Sonata\DoctrineORMAdminBundle\Model\ModelManager.php on line 416 and defined in
C:\wamp\www\sonata\app\cache\dev\classes.php line 8120
anybody can help????
Ok thx for you're answer there is the code
Symfony 2.4.1
the entity
<?php
namespace Tic\ClasseBundle\Entity;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Doctrine\ORM\Mapping as ORM;
/**
* Groupe
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="Tic\ClasseBundle\Entity\GroupeRepository")
*/
class Groupe extends Admin
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="groupe", type="string", length=255)
*/
private $groupe;
/**
* #var string
*
* #ORM\Column(name="enseignant", type="string", length=255)
*/
private $enseignant;
/**
* #var string
*
* #ORM\Column(name="grepere", type="string", length=255)
*/
private $grepere;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set groupe
*
* #param string $groupe
* #return Groupe
*/
public function setGroupe($groupe)
{
$this->groupe = $groupe;
return $this;
}
/**
* Get groupe
*
* #return string
*/
public function getGroupe()
{
return $this->groupe;
}
/**
* Set enseignant
*
* #param string $enseignant
* #return Groupe
*/
public function setEnseignant($enseignant)
{
$this->enseignant = $enseignant;
return $this;
}
/**
* Get enseignant
*
* #return string
*/
public function getEnseignant()
{
return $this->enseignant;
}
/**
* Set grepere
*
* #param string $grepere
* #return Groupe
*/
public function setGrepere($grepere)
{
$this->grepere = $grepere;
return $this;
}
/**
* Get grepere
*
* #return string
*/
public function getGrepere()
{
return $this->grepere;
}
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('enseignant', 'text',array('label'=>'Enseignants(es)'))
->add('groupe', 'text',array('label'=>'Groupe'))
->add('grepere', 'text',array('label'=>'Groupe Repere')) //if no type is specified, SonataAdminBundle tries to guess it
;
}
// Fields to be shown on filter forms
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('enseignant')
->add('grepere')
;
}
// Fields to be shown on lists
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('enseignant')
->add('grepere')
->add('groupe')
;
}
}
the config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: #TicClasseBundle/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_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%"
# 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 }
sonata_admin:
title: Gestion de classe
sonata_block:
default_contexts: [cms]
blocks:
# Enable the SonataAdminBundle block
sonata.admin.block.admin_list:
contexts: [admin]
# Your other blocks
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
currency: SonataAdminBundle:CRUD:list_currency.html.twig
percent: SonataAdminBundle:CRUD:list_percent.html.twig
choice: SonataAdminBundle:CRUD:list_choice.html.twig
url: SonataAdminBundle:CRUD:list_url.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
currency: SonataAdminBundle:CRUD:base_currency.html.twig
percent: SonataAdminBundle:CRUD:base_percent.html.twig
choice: SonataAdminBundle:CRUD:show_choice.html.twig
url: SonataAdminBundle:CRUD:show_url.html.twig
and the admin.yml
services:
sonata.admin.post:
class: Tic\ClasseBundle\Entity\Groupe
tags:
- { name: sonata.admin, manager_type: orm, group: "Gestion de classe", label: "Groupe" }
arguments:
- ~
- Tic\ClasseBundle\Entity\Groupe
- ~
calls:
- [ setTranslationDomain, [AcmeDemoBundle]]
thax
Your entity class Groupe is incorrect.
It will not extend Sonata admin class.
Methods configureListFields, configureFormFields, configureDatagridFilters should not be here. They must be in separate admin class(an analog symfony controller class)
Example:
<?php
namespace Tic\ClasseBundle\Controller\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
class GroupeAdmin extends Admin
{
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id')
->addIdentifier('name')
->add('country');
}
protected function configureFormFields(FormMapper $form)
{
$form
->add('id', null, [
'attr' => [
'readonly' => true,
],
])
->add('name')
->add('country');
}
protected function configureDatagridFilters(DatagridMapper $filter)
{
$filter
->add('id')
->add('name')
->add('country');
}
}
The entity and admin page should be separated from each other. Your entity shouldn't extend the Admin class Sonata provides, but you should create a new file instead which extend the Admin class.
sonata.admin.post:
class: Tic\ClasseBundle\Admin\AdminGroupe /*Locating the admin file*/
tags:
- { name: sonata.admin, manager_type: orm, group: "Gestion de classe", label: "Groupe" }
arguments:
- ~
- Tic\ClasseBundle\Entity\Groupe
- ~
calls:
- [ setTranslationDomain, [AcmeDemoBundle]]
I highly suggest to read the documentation (again) Sonata provides see: https://sonata-project.org/bundles/admin/3-x/doc/getting_started/creating_an_admin.html
I'm new Symfony2 user and I need help!
I have two Bundles with entities:
// My\FooBundle\Entity\Foo.php
namespace My\FooBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Table(name="foo")
* #ORM\Entity
*/
class Foo
{
/*...*/
/**
* #ORM\OneToOne(targetEntity="My\BarBundle\Entity\Bar")
*/
private $bar;
}
And in another bundle:
// My\BarBundle\Entity\Bar.php
namespace My\BarBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Table(name="bar")
* #ORM\Entity
*/
class Bar
{
/*...*/
/**
* #ORM\Column(name="name", nullable=false)
*/
private $name;
}
And my config.yml:
doctrine:
dbal:
default_connection: foo
connections:
foo:
dbname: "foo"
bar:
dbname: "bar"
orm:
entity_managers:
foo:
connection: foo
mappings:
MyFooBundle: ~
MyBarBundle: ~
bar:
connection: bar
mappings:
MyBarBundle: ~
And SF creates Bar in Foo database.
Q: How do I create a relation between two connections in this situation?
Remove MyBarBundle bundle from foo connection.
Add database name to bar entity
// My\BarBundle\Entity\Bar.php
namespace My\BarBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Table(name="bar.bar")
* #ORM\Entity
*/
class Bar
{
/*...*/
/**
* #ORM\Column(name="name", nullable=false)
*/
private $name;
}
And following strings to config.yml:
doctrine:
dbal:
default_connection: foo
connections:
foo:
dbname: "foo"
bar:
dbname: "bar"
orm:
entity_managers:
foo:
connection: foo
mappings:
MyFooBundle: ~
MyBarBundle:
type: "annotation"
dir: ..\..\My\BarBundle\Entity
bar:
connection: bar
mappings:
MyBarBundle:
type: "annotation"
dir: ..\..\My\BarBundle\Entity
I'm migrating my Symfony 2.0 project to version 2.1rc1. After installing the stof/doctrine-extensions-bundle and the gedmo/doctrine-extensions and test my application I get the following error:
No identifier/primary key specified for Entity "Company\TestBundle\Entity\PageTranslation" sub class of "Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation". Every Entity must have an identifier/primary key.
My config.yml looks like this:
# Doctrine Configuration
doctrine:
dbal:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
charset: UTF8
orm:
auto_generate_proxy_classes: %kernel.debug%
connection: default
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 # this one is optional and 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 # this one is optional and will default to the name set for the mapping
is_bundle: false
stof_doctrine_extensions:
default_locale: en
translation_fallback: true
orm:
default:
translatable: true
sluggable: true
According to the documentation of StofDoctrineExtensionsBundle this should be fine. The only thing I'm not sure of is the auto_mapping: true option.
The only code I've changed in my project is in my CategoryTranslation class. I've replaced:
use Stof\DoctrineExtensionsBundle\Entity\AbstractTranslation;
by:
use Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation;
Because the Stof-bundle doesn't have an AbstractTranslation class anymore.
Can someone tell me how I can fix this?
My PageTranslation entity before:
class PageTranslation extends AbstractTranslation
{
/**
* All required columns are mapped through inherited superclass
*/
}
My PageTranslation entity after generating the entities on the commandline:
class PageTranslation extends AbstractTranslation
{
/**
* All required columns are mapped through inherited superclass
*/
/**
* #var integer $id
*/
private $id;
/**
* #var string $locale
*/
private $locale;
.....etc....
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set locale
*
* #param string $locale
* #return PageTranslation
*/
public function setLocale($locale)
{
$this->locale = $locale;
return $this;
}
/**
* Get locale
*
* #return string
*/
public function getLocale()
{
return $this->locale;
}
..etc....
}
If you are using StofDoctrineExtensions you don't need gedmo/doctrine-extensions. Also isn't necessary to generate anything in PageTranslation