0
symfony 3에서 sonata admin. 나는 몇몇 실재물을 만들고 나는 "이름"가 유일 할 것이라는 점을 가진 실재물이있다.Sonata 관리자가있는 고유 한 필드 - SYMFONY
YML과 함께 doctrine 사용. 유효성 검사 제한을 시도하지만 성공하지 못했습니다! 나는이 시도하지만 지적은
분야 이름을 가진 내 객체
<?php
namespace AdminBundle\Entity;
use Symfony\Bridge\Doctrine\Validator\Constraints as DoctrineAssert;
/**
* Organisation
*/
class Organisation
{
/**
* @var int
*/
private $id;
/**
* @var string(200)
*/
private $name;
/**
* @var int
*/
private $organisationtype=null;
/**
* @var string
*/
private $description=null;
/**
* @var string(100)
*/
private $address1=null;
/**
* @var string(100)
*/
private $address2=null;
/**
* @var string(11)
*/
private $zipcode=null;
/**
* @var string(50)
*/
private $city=null;
/**
* @var int
*/
private $country=null;
/**
* @var string(60)
*/
private $phone=null;
/**
* @var string(100)
*/
private $URL=null;
/**
* @var string(50)
*/
private $email=null;
/**
* @var string(50)
*/
private $comments=null;
/**
* @var \DateTime
*/
private $created;
/**
* @var \DateTime
*/
private $updated;
public function setCreatedAtValue()
{
$this->created = new \DateTime();
}
public function setUpdatedAtValue()
{
$this->updated = new \DateTime();
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
public function __toString(){
return $this->name;
}
/**
* Set name
*
* @param string $name
*
* @return Organisation
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set organisationtype
*
* @param $organisationtype
*
* @return Organisation
*/
public function setOrganisationtype($organisationtype)
{
$this->organisationtype = $organisationtype;
return $this;
}
/**
* Get organisationtype
*
* @return int
*/
public function getOrganisationtype()
{
return $this->organisationtype;
}
/**
* Set description
*
* @param string $description
*
* @return Organisation
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set address1
*
* @param string $address1
*
* @return Organisation
*/
public function setAddress1($address1)
{
$this->address1 = $address1;
return $this;
}
/**
* Get address1
*
* @return string
*/
public function getAddress1()
{
return $this->address1;
}
/**
* Set address2
*
* @param string $address2
*
* @return Organisation
*/
public function setAddress2($address2)
{
$this->address2 = $address2;
return $this;
}
/**
* Get address2
*
* @return string
*/
public function getAddress2()
{
return $this->address2;
}
/**
* Set zipcode
*
* @param int $zipcode
*
* @return Organisation
*/
public function setZipcode($zipcode)
{
$this->zipcode = $zipcode;
return $this;
}
/**
* Get zipcode
*
* @return string
*/
public function getZipcode()
{
return $this->zipcode;
}
/**
* Set city
*
* @param string $city
*
* @return Organisation
*/
public function setCity($city)
{
$this->city = $city;
return $this;
}
/**
* Get city
*
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* Set country
*
* @param $country
*
* @return Organisation
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* Get country
*
* @return int
*/
public function getCountry()
{
return $this->country;
}
/**
* Set phone
*
* @param int $phone
*
* @return Organisation
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* Get phone
*
* @return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set URL
*
* @param string $URL
*
* @return Organisation
*/
public function setURL($URL)
{
$this->URL = $URL;
return $this;
}
/**
* Get URL
*
* @return string
*/
public function getURL()
{
return $this->URL;
}
/**
* Set email
*
* @param string $email
*
* @return Organisation
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set comments
*
* @param string $comments
*
* @return Organisation
*/
public function setComments($comments)
{
$this->comments = $comments;
return $this;
}
/**
* Get comments
*
* @return string
*/
public function getComments()
{
return $this->comments;
}
/**
* Set created
*
* @param \DateTime $created
* @return Contact
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* @return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated
*
* @param \DateTime $updated
* @return Contact
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated
*
* @return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
}
내 교리 파일 일 :
AdminBundle\Entity\Organisation:
type: entity
table: null
repositoryClass: AdminBundle\Repository\OrganisationRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
name:
type: string
length: 200
unique: true
description:
type: text
nullable: TRUE
address1:
type: string
length: 100
nullable: TRUE
address2:
type: string
length: 100
nullable: TRUE
zipcode:
type: string
length: 11
nullable: TRUE
city:
type: string
length: 50
nullable: TRUE
phone:
type: string
length: 60
nullable: TRUE
URL:
type: string
length: 100
nullable: TRUE
email:
type: string
length: 50
nullable: TRUE
comments:
type: string
length: 255
nullable: TRUE
created:
type: datetime
nullable: true
gedmo:
timestampable:
on: create
updated:
type: datetime
nullable: true
gedmo:
timestampable:
on: update
uniqueConstraints:
search_idx:
columns: [ name ]
lifecycleCallbacks:
prePersist: [ setCreatedAtValue,setUpdatedAtValue ]
preUpdate: [ setUpdatedAtValue ]
manyToOne:
organisationtype:
targetEntity: AdminBundle\Entity\Organisation_type
joinColumn:
name: organisationtype
referencedColumnName: id
nullable: TRUE
country:
targetEntity: AdminBundle\Entity\Country
joinColumn:
name: country
referencedColumnName: id
nullable: TRUE
내 validation.orm.yml
AdminBundle\Entity\Organisation:
constraints:
- Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity:
fields: name
message: 'Ce nom est dèjà utilisé'
을 및 내 구성 파일
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: "@AdminBundle/Resources/config/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: en
framework:
#esi: ~
translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enabled: true, enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
fragments: ~
http_method_override: true
assets: ~
# 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.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%"
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 }
# FOSUserBundle
fos_user:
db_driver: orm
firewall_name: main
use_listener: false
user_class: UserBundle\Entity\User
# SonataAdminBundle
내가