I have created a symfony2 project and custom Authentication Provider (http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html) is used. my new task is to create an E-commerce application in sylius which should work alongside with my current symfony2 project. i want to make my current user table in symfony2 project as user provider in sylius...is it possible to create such project..... since fosUserBundle and fosOauthServer bundel are installed in sylius how can i override these bundles with my custom authentication mechanism
My symfony2 project configurations are mentioned below
I tried the following in security.yml
security:
encoders:
AppBundle\Entity\Users:
algorithm: bcrypt
providers:
our_db_provider:
entity:
class: AppBundle:Users
api_key_user_provider:
id: api_key_user_provider
firewalls:
dev:
pattern: ^/(_(profiler|wdt|error)|css|images|js)/
security: false
api:
pattern: ^/api
stateless: true
simple_preauth:
authenticator: apikey_authenticator
provider: api_key_user_provider
web:
anonymous: ~
http_basic: ~
provider: our_db_provider
form_login:
login_path: /login
check_path: /login_check
this is my user class
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* Users
*
* #ORM\Table(name="users", uniqueConstraints= {#ORM\UniqueConstraint(name="users_user_name_unique", columns={"user_name"}), #ORM\UniqueConstraint(name="users_xmpp_password_unique", columns= {"xmpp_password"})})
* #ORM\Entity(repositoryClass="AppBundle\Entity\UsersRepository")
*/
class Users implements UserInterface, \Serializable {
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var integer
*
* #ORM\Column(name="parent_id", type="integer", nullable=false)
*/
private $parentId;
/**
* #var string
*
* #ORM\Column(name="first_name", type="string", length=100, nullable=false)
*/
private $firstName;
/**
* #var string
*
* #ORM\Column(name="last_name", type="string", length=100, nullable=false)
*/
private $lastName;
/**
* #var string
*
* #ORM\Column(name="user_name", type="string", length=120, nullable=false)
*/
private $userName;
/**
* #var string
*
* #ORM\Column(name="reg_type", type="string", length=20, nullable=false)
*/
private $regType;
/**
* #var string
*
* #ORM\Column(name="oauth_uid", type="string", length=255, nullable=false)
*/
private $oauthUid;
/**
* #var boolean
*
* #ORM\Column(name="active", type="boolean", nullable=false)
*/
private $active;
/**
* #var string
*
* #ORM\Column(name="email", type="string", length=100, nullable=false)
*/
private $email;
/**
* #var string
*
* #ORM\Column(name="password", type="string", length=150, nullable=false)
*/
private $password;
/**
* #var string
*
* #ORM\Column(name="xmpp_password", type="string", length=20, nullable=false)
*/
private $xmppPassword;
/**
* #var \DateTime
*
* #ORM\Column(name="created_at", type="datetime", nullable=false)
*/
private $createdAt = '0000-00-00 00:00:00';
/**
* #var \DateTime
*
* #ORM\Column(name="updated_at", type="datetime", nullable=false)
*/
private $updatedAt = '0000-00-00 00:00:00';
/**
* #var \DateTime
*
* #ORM\Column(name="deleted_at", type="datetime", nullable=true)
*/
private $deletedAt;
/**
* #var string
*
* #ORM\Column(name="activation_code", type="string", length=50, nullable=true)
*/
private $activationCode;
/**
* #var string
*
* #ORM\Column(name="user_profile_pic", type="string", length=200, nullable=false)
*/
private $userProfilePic = 'uploads/defaults/user/profile_pic.jpg';
/**
* #var string
*
* #ORM\Column(name="user_timeline_pic", type="string", length=200, nullable=false)
*/
private $userTimelinePic = 'uploads/defaults/user/timeline_pic.jpg';
/**
* #var string
*
* #ORM\Column(name="country", type="string", length=50, nullable=false)
*/
private $country;
/**
* #var string
*
* #ORM\Column(name="state", type="string", length=50, nullable=false)
*/
private $state;
/**
* #var string
*
* #ORM\Column(name="city", type="string", length=50, nullable=false)
*/
private $city;
/**
* #var string
*
* #ORM\Column(name="hobbies", type="string", length=100, nullable=false)
*/
private $hobbies;
/**
* #var string
*
* #ORM\Column(name="interests", type="string", length=100, nullable=false)
*/
private $interests;
/**
* #var string
*
* #ORM\Column(name="about", type="string", length=500, nullable=false)
*/
private $about;
/**
* #var boolean
*
* #ORM\Column(name="gender", type="boolean", nullable=false)
*/
private $gender;
/**
* #var \DateTime
*
* #ORM\Column(name="dob", type="date", nullable=false)
*/
private $dob;
/**
* #var integer
*
* #ORM\Column(name="quickblox_id", type="integer", nullable=false)
*/
private $quickbloxId;
/**
* #var boolean
*
* #ORM\Column(name="privacy", type="boolean", nullable=false)
*/
private $privacy = '0';
/**
* #var string
*
* #ORM\Column(name="school", type="string", length=255, nullable=false)
*/
private $school;
/**
* #var string
*
* #ORM\Column(name="college", type="string", length=255, nullable=false)
*/
private $college;
/**
* #var string
*
* #ORM\Column(name="work", type="string", length=255, nullable=false)
*/
private $work;
/**
* #var string
*
* #ORM\Column(name="relationship_status", type="string", length=50, nullable=false)
*/
private $relationshipStatus;
public function getSalt() {
// you *may* need a real salt depending on your encoder
// see section on salt below
return null;
}
public function getRoles() {
return array('ROLE_API');
}
public function eraseCredentials() {
}
/** #see \Serializable::serialize() */
public function serialize() {
return serialize(array(
$this->id,
$this->email,
// see section on salt below
// $this->salt,
));
}
/** #see \Serializable::unserialize() */
public function unserialize($serialized) {
list (
$this->id,
$this->email,
// see section on salt below
// $this->salt
) = unserialize($serialized);
}
/**
* Get id
*
* #return integer
*/
public function getId() {
return $this->id;
}
/**
* Set parentId
*
* #param integer $parentId
* #return Users
*/
public function setParentId($parentId) {
$this->parentId = $parentId;
return $this;
}
/**
* Get parentId
*
* #return integer
*/
public function getParentId() {
return $this->parentId;
}
/**
* Set firstName
*
* #param string $firstName
* #return Users
*/
public function setFirstName($firstName) {
$this->firstName = $firstName;
return $this;
}
/**
* Get firstName
*
* #return string
*/
public function getFirstName() {
return $this->firstName;
}
/**
* Set lastName
*
* #param string $lastName
* #return Users
*/
public function setLastName($lastName) {
$this->lastName = $lastName;
return $this;
}
/**
* Get lastName
*
* #return string
*/
public function getLastName() {
return $this->lastName;
}
/**
* Set userName
*
* #param string $userName
* #return Users
*/
public function setUserName($userName) {
$this->userName = $userName;
return $this;
}
/**
* Get userName
*
* #return string
*/
public function getUserName() {
return $this->email;
}
/**
* Set regType
*
* #param string $regType
* #return Users
*/
public function setRegType($regType) {
$this->regType = $regType;
return $this;
}
/**
* Get regType
*
* #return string
*/
public function getRegType() {
return $this->regType;
}
/**
* Set oauthUid
*
* #param string $oauthUid
* #return Users
*/
public function setOauthUid($oauthUid) {
$this->oauthUid = $oauthUid;
return $this;
}
/**
* Get oauthUid
*
* #return string
*/
public function getOauthUid() {
return $this->oauthUid;
}
/**
* Set active
*
* #param boolean $active
* #return Users
*/
public function setActive($active) {
$this->active = $active;
return $this;
}
/**
* Get active
*
* #return boolean
*/
public function getActive() {
return $this->active;
}
/**
* Set email
*
* #param string $email
* #return Users
*/
public function setEmail($email) {
$this->email = $email;
return $this;
}
/**
* Get email
*
* #return string
*/
public function getEmail() {
return $this->email;
}
/**
* Set password
*
* #param string $password
* #return Users
*/
public function setPassword($password) {
$this->password = $password;
return $this;
}
/**
* Get password
*
* #return string
*/
public function getPassword() {
return $this->password;
}
/**
* Set xmppPassword
*
* #param string $xmppPassword
* #return Users
*/
public function setXmppPassword($xmppPassword) {
$this->xmppPassword = $xmppPassword;
return $this;
}
/**
* Get xmppPassword
*
* #return string
*/
public function getXmppPassword() {
return $this->xmppPassword;
}
/**
* Set createdAt
*
* #param \DateTime $createdAt
* #return Users
*/
public function setCreatedAt($createdAt) {
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* #return \DateTime
*/
public function getCreatedAt() {
return $this->createdAt;
}
/**
* Set updatedAt
*
* #param \DateTime $updatedAt
* #return Users
*/
public function setUpdatedAt($updatedAt) {
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* #return \DateTime
*/
public function getUpdatedAt() {
return $this->updatedAt;
}
/**
* Set deletedAt
*
* #param \DateTime $deletedAt
* #return Users
*/
public function setDeletedAt($deletedAt) {
$this->deletedAt = $deletedAt;
return $this;
}
/**
* Get deletedAt
*
* #return \DateTime
*/
public function getDeletedAt() {
return $this->deletedAt;
}
/**
* Set activationCode
*
* #param string $activationCode
* #return Users
*/
public function setActivationCode($activationCode) {
$this->activationCode = $activationCode;
return $this;
}
/**
* Get activationCode
*
* #return string
*/
public function getActivationCode() {
return $this->activationCode;
}
/**
* Set userProfilePic
*
* #param string $userProfilePic
* #return Users
*/
public function setUserProfilePic($userProfilePic) {
$this->userProfilePic = $userProfilePic;
return $this;
}
/**
* Get userProfilePic
*
* #return string
*/
public function getUserProfilePic() {
return $this->userProfilePic;
}
/**
* Set userTimelinePic
*
* #param string $userTimelinePic
* #return Users
*/
public function setUserTimelinePic($userTimelinePic) {
$this->userTimelinePic = $userTimelinePic;
return $this;
}
/**
* Get userTimelinePic
*
* #return string
*/
public function getUserTimelinePic() {
return $this->userTimelinePic;
}
/**
* Set country
*
* #param string $country
* #return Users
*/
public function setCountry($country) {
$this->country = $country;
return $this;
}
/**
* Get country
*
* #return string
*/
public function getCountry() {
return $this->country;
}
/**
* Set state
*
* #param string $state
* #return Users
*/
public function setState($state) {
$this->state = $state;
return $this;
}
/**
* Get state
*
* #return string
*/
public function getState() {
return $this->state;
}
/**
* Set city
*
* #param string $city
* #return Users
*/
public function setCity($city) {
$this->city = $city;
return $this;
}
/**
* Get city
*
* #return string
*/
public function getCity() {
return $this->city;
}
/**
* Set hobbies
*
* #param string $hobbies
* #return Users
*/
public function setHobbies($hobbies) {
$this->hobbies = $hobbies;
return $this;
}
/**
* Get hobbies
*
* #return string
*/
public function getHobbies() {
return $this->hobbies;
}
/**
* Set interests
*
* #param string $interests
* #return Users
*/
public function setInterests($interests) {
$this->interests = $interests;
return $this;
}
/**
* Get interests
*
* #return string
*/
public function getInterests() {
return $this->interests;
}
/**
* Set about
*
* #param string $about
* #return Users
*/
public function setAbout($about) {
$this->about = $about;
return $this;
}
/**
* Get about
*
* #return string
*/
public function getAbout() {
return $this->about;
}
/**
* Set gender
*
* #param boolean $gender
* #return Users
*/
public function setGender($gender) {
$this->gender = $gender;
return $this;
}
/**
* Get gender
*
* #return boolean
*/
public function getGender() {
return $this->gender;
}
/**
* Set dob
*
* #param \DateTime $dob
* #return Users
*/
public function setDob($dob) {
$this->dob = $dob;
return $this;
}
/**
* Get dob
*
* #return \DateTime
*/
public function getDob() {
return $this->dob;
}
/**
* Set quickbloxId
*
* #param integer $quickbloxId
* #return Users
*/
public function setQuickbloxId($quickbloxId) {
$this->quickbloxId = $quickbloxId;
return $this;
}
/**
* Get quickbloxId
*
* #return integer
*/
public function getQuickbloxId() {
return $this->quickbloxId;
}
/**
* Set privacy
*
* #param boolean $privacy
* #return Users
*/
public function setPrivacy($privacy) {
$this->privacy = $privacy;
return $this;
}
/**
* Get privacy
*
* #return boolean
*/
public function getPrivacy() {
return $this->privacy;
}
/**
* Set school
*
* #param string $school
* #return Users
*/
public function setSchool($school) {
$this->school = $school;
return $this;
}
/**
* Get school
*
* #return string
*/
public function getSchool() {
return $this->school;
}
/**
* Set college
*
* #param string $college
* #return Users
*/
public function setCollege($college) {
$this->college = $college;
return $this;
}
/**
* Get college
*
* #return string
*/
public function getCollege() {
return $this->college;
}
/**
* Set work
*
* #param string $work
* #return Users
*/
public function setWork($work) {
$this->work = $work;
return $this;
}
/**
* Get work
*
* #return string
*/
public function getWork() {
return $this->work;
}
/**
* Set relationshipStatus
*
* #param string $relationshipStatus
* #return Users
*/
public function setRelationshipStatus($relationshipStatus) {
$this->relationshipStatus = $relationshipStatus;
return $this;
}
/**
* Get relationshipStatus
*
* #return string
*/
public function getRelationshipStatus() {
return $this->relationshipStatus;
}
You can find the answer here https://github.com/Sylius/Sylius/issues/2931.
Related
Hello I´m new on symfony.
I made an entity with doctrine:generate:entity and return me this:
<?php
namespace LoginBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Users
*
* #ORM\Table(name="users")
* #ORM\Entity
*/
class Users
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="SEQUENCE")
* #ORM\SequenceGenerator(sequenceName="users_id_seq", allocationSize=1, initialValue=1)
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=30, nullable=false)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="lastname", type="string", length=30, nullable=false)
*/
private $lastname;
/**
* #var string
*
* #ORM\Column(name="password", type="string", length=200, nullable=false)
*/
private $password;
/**
* #var \DateTime
*
* #ORM\Column(name="ts", type="datetime", nullable=false)
*/
private $ts = 'now()';
/**
* #var string
*
* #ORM\Column(name="mail", type="string", length=150, nullable=false)
*/
private $mail;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* #param string $name
*
* #return Users
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set lastname
*
* #param string $lastname
*
* #return Users
*/
public function setLastname($lastname)
{
$this->lastname = $lastname;
return $this;
}
/**
* Get lastname
*
* #return string
*/
public function getLastname()
{
return $this->lastname;
}
/**
* Set password
*
* #param string $password
*
* #return Users
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* #return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set ts
*
* #param \DateTime $ts
*
* #return Users
*/
public function setTs($ts)
{
$this->ts = $ts;
return $this;
}
/**
* Get ts
*
* #return \DateTime
*/
public function getTs()
{
return $this->ts;
}
/**
* Set mail
*
* #param string $mail
*
* #return Users
*/
public function setMail($mail)
{
$this->mail = $mail;
return $this;
}
/**
* Get mail
*
* #return string
*/
public function getMail()
{
return $this->mail;
}
}
The problem is the line with the timestamp
private $ts = 'now()';
And now i´m getting this error
Call to a member function format() on string
in vendor\doctrine\dbal\lib\Doctrine\DBAL\Types\DateTimeType.php (line 53)
public function convertToDatabaseValue($value, AbstractPlatform $platform) { return ($value !== null) ? $value->format($platform->getDateTimeFormatString()) : null; }
Thanks in advance
If you want to get the current date and time, you need to set current dateTime. You need create __construct method:
public function __construct()
{
$this->setTs(new \DateTime());
}
I have project which have different bundles. I want to create or divide entities in different bundle how can I create this. I am new in symfony please help me . I created but I can not do mapping correctly . a table which have primary key can't use in another bundle.
Here is my Entity
namespace DomainBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* WebsiteDomainConfigTest
*
* #ORM\Table(name="website_domain_config_test", indexes={#ORM\Index(name="fk_website_domain_config_test_1_idx", columns={"vendor_id"}), #ORM\Index(name="fk_website_domain_config_test_2_idx", columns={"country_id"})})
* #ORM\Entity
*/
class WebsiteDomainConfigTest
{
/**
* #var string
*
* #ORM\Column(name="domain", type="string", length=255, nullable=true)
*/
private $domain;
/**
* #var string
*
* #ORM\Column(name="vendor_code", type="string", length=15, nullable=true)
*/
private $vendorCode;
/**
* #var string
*
* #ORM\Column(name="domain_path", type="string", length=255, nullable=true)
*/
private $domainPath;
/**
* #var string
*
* #ORM\Column(name="assets_path", type="string", length=45, nullable=true)
*/
private $assetsPath;
/**
* #var string
*
* #ORM\Column(name="language", type="string", length=3, nullable=true)
*/
private $language;
/**
* #var string
*
* #ORM\Column(name="affiliate", type="string", length=25, nullable=true)
*/
private $affiliate;
/**
* #var string
*
* #ORM\Column(name="affiliate_logo", type="string", length=255, nullable=true)
*/
private $affiliateLogo;
/**
* #var string
*
* #ORM\Column(name="affiliate_address", type="string", length=255, nullable=true)
*/
private $affiliateAddress;
/**
* #var integer
*
* #ORM\Column(name="status", type="integer", nullable=true)
*/
private $status;
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var \MobileSplash\SplashRequestBundle\Entity\Countries
*
* #ORM\ManyToOne(targetEntity="MobileSplash\SplashRequestBundle\Entity\Countries")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="country_id", referencedColumnName="id")
* })
*/
private $country;
/**
* #var \MobileSplash\SplashRequestBundle\Entity\Vendors
*
* #ORM\ManyToOne(targetEntity="MobileSplash\SplashRequestBundle\Entity\Vendors")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="vendor_id", referencedColumnName="id")
* })
*/
private $vendor;
/**
* Set domain
*
* #param string $domain
* #return WebsiteDomainConfigTest
*/
public function setDomain($domain)
{
$this->domain = $domain;
return $this;
}
/**
* Get domain
*
* #return string
*/
public function getDomain()
{
return $this->domain;
}
/**
* Set vendorCode
*
* #param string $vendorCode
* #return WebsiteDomainConfigTest
*/
public function setVendorCode($vendorCode)
{
$this->vendorCode = $vendorCode;
return $this;
}
/**
* Get vendorCode
*
* #return string
*/
public function getVendorCode()
{
return $this->vendorCode;
}
/**
* Set domainPath
*
* #param string $domainPath
* #return WebsiteDomainConfigTest
*/
public function setDomainPath($domainPath)
{
$this->domainPath = $domainPath;
return $this;
}
/**
* Get domainPath
*
* #return string
*/
public function getDomainPath()
{
return $this->domainPath;
}
/**
* Set assetsPath
*
* #param string $assetsPath
* #return WebsiteDomainConfigTest
*/
public function setAssetsPath($assetsPath)
{
$this->assetsPath = $assetsPath;
return $this;
}
/**
* Get assetsPath
*
* #return string
*/
public function getAssetsPath()
{
return $this->assetsPath;
}
/**
* Set language
*
* #param string $language
* #return WebsiteDomainConfigTest
*/
public function setLanguage($language)
{
$this->language = $language;
return $this;
}
/**
* Get language
*
* #return string
*/
public function getLanguage()
{
return $this->language;
}
/**
* Set affiliate
*
* #param string $affiliate
* #return WebsiteDomainConfigTest
*/
public function setAffiliate($affiliate)
{
$this->affiliate = $affiliate;
return $this;
}
/**
* Get affiliate
*
* #return string
*/
public function getAffiliate()
{
return $this->affiliate;
}
/**
* Set affiliateLogo
*
* #param string $affiliateLogo
* #return WebsiteDomainConfigTest
*/
public function setAffiliateLogo($affiliateLogo)
{
$this->affiliateLogo = $affiliateLogo;
return $this;
}
/**
* Get affiliateLogo
*
* #return string
*/
public function getAffiliateLogo()
{
return $this->affiliateLogo;
}
/**
* Set affiliateAddress
*
* #param string $affiliateAddress
* #return WebsiteDomainConfigTest
*/
public function setAffiliateAddress($affiliateAddress)
{
$this->affiliateAddress = $affiliateAddress;
return $this;
}
/**
* Get affiliateAddress
*
* #return string
*/
public function getAffiliateAddress()
{
return $this->affiliateAddress;
}
/**
* Set status
*
* #param integer $status
* #return WebsiteDomainConfigTest
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* Get status
*
* #return integer
*/
public function getStatus()
{
return $this->status;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set country
*
* #param \MobileSplash\SplashRequestBundle\Entity\Countries $country
* #return WebsiteDomainConfigTest
*/
public function setCountry(\MobileSplash\SplashRequestBundle\Entity\Countries $country = null)
{
$this->country = $country;
return $this;
}
/**
* Get country
*
* #return \MobileSplash\SplashRequestBundle\Entity\Countries
*/
public function getCountry()
{
return $this->country;
}
/**
* Set vendor
*
* #param \MobileSplash\SplashRequestBundle\Entity\Vendors $vendor
* #return WebsiteDomainConfigTest
*/
public function setVendor(\MobileSplash\SplashRequestBundle\Entity\Vendors $vendor = null)
{
$this->vendor = $vendor;
return $this;
}
/**
* Get vendor
*
* #return \MobileSplash\SplashRequestBundle\Entity\Vendors
*/
public function getVendor()
{
return $this->vendor;
}
}
in your annotation use namespace like this:
targetEntity="\Mj\FooBundle\Entity\Foo"
Problem - I want to save the data that is submitted from the form, when i am saving it to MySQL getting error as -
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'updated' cannot be null
But I have given the update column the default value as 0000-00-00 00:00:00 , by default it must take the default value.
I am using the "prepersist" technique to add the code before saving it to MySQL.
The following is my "prepersist" code snippet from which the above error got generated-
public function setBeforeInsertData() {
$this->added = new \DateTime();
}
I have used the following code to overcome the error just for the time being I know that its a wrong approach.
public function setBeforeInsertData() {
$this->added = new \DateTime();
$this->updated = new \DateTime();
}
The following is the Entity for the respective table -
<?php
namespace Skerp\InventoryBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* InventoryLocation
*
* #ORM\Table(name="inventory_location")
* #ORM\Entity
* #ORM\HasLifecycleCallbacks()
*/
class InventoryLocation
{
/**
* #var string
*
* #ORM\Column(name="locName", type="string", length=50, nullable=false)
*/
private $locname;
/**
* #var string
*
* #ORM\Column(name="address1", type="string", length=50, nullable=false)
*/
private $address1;
/**
* #var string
*
* #ORM\Column(name="address2", type="string", length=50, nullable=true)
*/
private $address2;
/**
* #var string
*
* #ORM\Column(name="address3", type="string", length=50, nullable=true)
*/
private $address3;
/**
* #var string
*
* #ORM\Column(name="city", type="string", length=40, nullable=false)
*/
private $city;
/**
* #var string
*
* #ORM\Column(name="zipCode", type="string", length=5, nullable=false)
*/
private $zipcode;
/**
* #var string
*
* #ORM\Column(name="state", type="string", length=40, nullable=false)
*/
private $state;
/**
* #var string
*
* #ORM\Column(name="country", type="string", length=40, nullable=false)
*/
private $country;
/**
* #var string
*
* #ORM\Column(name="telephone", type="string", length=20, nullable=true)
*/
private $telephone;
/**
* #var string
*
* #ORM\Column(name="fax", type="string", length=30, nullable=true)
*/
private $fax;
/**
* #var string
*
* #ORM\Column(name="email", type="string", length=40, nullable=true)
*/
private $email;
/**
* #var string
*
* #ORM\Column(name="contactNo", type="string", length=20, nullable=false)
*/
private $contactno;
/**
* #var string
*
* #ORM\Column(name="addedBy", type="string", length=100, nullable=true)
*/
private $addedby;
/**
* #var \DateTime
*
* #ORM\Column(name="added", type="datetime", nullable=true)
*/
private $added;
/**
* #var \DateTime
*
* #ORM\Column(name="updated", type="datetime", nullable=false)
*/
private $updated;
/**
* #var integer
*
* #ORM\Column(name="inventLocId", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $inventlocid;
/**
* Set locname
*
* #param string $locname
* #return InventoryLocation
*/
public function setLocname($locname)
{
$this->locname = $locname;
return $this;
}
/**
* Get locname
*
* #return string
*/
public function getLocname()
{
return $this->locname;
}
/**
* Set address1
*
* #param string $address1
* #return InventoryLocation
*/
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 InventoryLocation
*/
public function setAddress2($address2)
{
$this->address2 = $address2;
return $this;
}
/**
* Get address2
*
* #return string
*/
public function getAddress2()
{
return $this->address2;
}
/**
* Set address3
*
* #param string $address3
* #return InventoryLocation
*/
public function setAddress3($address3)
{
$this->address3 = $address3;
return $this;
}
/**
* Get address3
*
* #return string
*/
public function getAddress3()
{
return $this->address3;
}
/**
* Set city
*
* #param string $city
* #return InventoryLocation
*/
public function setCity($city)
{
$this->city = $city;
return $this;
}
/**
* Get city
*
* #return string
*/
public function getCity()
{
return $this->city;
}
/**
* Set zipcode
*
* #param string $zipcode
* #return InventoryLocation
*/
public function setZipcode($zipcode)
{
$this->zipcode = $zipcode;
return $this;
}
/**
* Get zipcode
*
* #return string
*/
public function getZipcode()
{
return $this->zipcode;
}
/**
* Set state
*
* #param string $state
* #return InventoryLocation
*/
public function setState($state)
{
$this->state = $state;
return $this;
}
/**
* Get state
*
* #return string
*/
public function getState()
{
return $this->state;
}
/**
* Set country
*
* #param string $country
* #return InventoryLocation
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* Get country
*
* #return string
*/
public function getCountry()
{
return $this->country;
}
/**
* Set telephone
*
* #param string $telephone
* #return InventoryLocation
*/
public function setTelephone($telephone)
{
$this->telephone = $telephone;
return $this;
}
/**
* Get telephone
*
* #return string
*/
public function getTelephone()
{
return $this->telephone;
}
/**
* Set fax
*
* #param string $fax
* #return InventoryLocation
*/
public function setFax($fax)
{
$this->fax = $fax;
return $this;
}
/**
* Get fax
*
* #return string
*/
public function getFax()
{
return $this->fax;
}
/**
* Set email
*
* #param string $email
* #return InventoryLocation
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* #return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set contactno
*
* #param string $contactno
* #return InventoryLocation
*/
public function setContactno($contactno)
{
$this->contactno = $contactno;
return $this;
}
/**
* Get contactno
*
* #return string
*/
public function getContactno()
{
return $this->contactno;
}
/**
* Set addedby
*
* #param string $addedby
* #return InventoryLocation
*/
public function setAddedby($addedby)
{
$this->addedby = $addedby;
return $this;
}
/**
* Get addedby
*
* #return string
*/
public function getAddedby()
{
return $this->addedby;
}
/**
* Set added
*
* #param \DateTime $added
* #return InventoryLocation
*/
public function setAdded($added)
{
$this->added = $added;
return $this;
}
/**
* Get added
*
* #return \DateTime
*/
public function getAdded()
{
return $this->added;
}
/**
* Set updated
*
* #param \DateTime $updated
* #return InventoryLocation
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated
*
* #return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Get inventlocid
*
* #return integer
*/
public function getInventlocid()
{
return $this->inventlocid;
}
/**
* #var integer
*/
private $id;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* #ORM\PrePersist
*/
public function setBeforeInsertData() {
$this->added = new \DateTime();
//$this->updated = new \DateTime();
}
}
Thanks in Advance.
Your entity class should have following annotation: #ORM\HasLifecycleCallbacks(). Your methods should have #ORM\PrePersist annotation. More info: http://symfony.com/doc/current/book/doctrine.html#lifecycle-callbacks
I have a basic view that I use on every page. In my basic view I have:
<div class="container">
{% block body %}
{% endblock %}
</div>
Where the body of every page comes. In my base view I have also a navigation. Now I would like to show a button depending on some data of the user logged in.
This is my case:
I have a table players with a FK user_id and a FK team_id. The user_id refers to my user table where the username, password, ... is saved. Now I would like to show the button depending on team_id in players table is NULL or not.
So I would need something like this:
if(is_null($user->getPlayer()->getTeam())
{
// DON'T SHOW BUTTON
}
else{
// SHOW BUTTON
}
But how I can use that data in my base view? (It's rendered on every page)
UPDATE:
My Users Entity:
<?php
namespace VolleyScout\VolleyScoutBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
/**
* Users
*
* #ORM\Table(name="users", indexes={#ORM\Index(name="fk_users_roles1_idx", columns={"role_id"})})
* #ORM\Entity
*/
class Users implements AdvancedUserInterface
{
/**
* #var string
*
* #ORM\Column(name="username", type="string", length=45, nullable=false)
*/
private $username;
/**
* #var string
*
* #ORM\Column(name="password", type="string", length=60, nullable=false)
*/
private $password;
/**
* #var string
*
* #ORM\Column(name="salt", type="string", length=30, nullable=false)
*/
private $salt;
/**
* #var string
*
* #ORM\Column(name="user_firstname", type="string", length=45, nullable=false)
*/
private $userFirstname;
/**
* #var string
*
* #ORM\Column(name="user_surname", type="string", length=255, nullable=false)
*/
private $userSurname;
/**
* #var string
*
* #ORM\Column(name="user_email", type="string", length=255, nullable=false)
*/
private $userEmail;
/**
* #var string
*
* #ORM\Column(name="user_type", type="string", nullable=false)
*/
private $userType;
/**
* #var string
*
* #ORM\Column(name="user_token", type="string", length=45, nullable=true)
*/
private $userToken;
/**
* #var \DateTime
*
* #ORM\Column(name="user_created", type="datetime", nullable=false)
*/
private $userCreated;
/**
* #var \DateTime
*
* #ORM\Column(name="user_modified", type="datetime", nullable=true)
*/
private $userModified;
/**
* #var \DateTime
*
* #ORM\Column(name="user_deleted", type="datetime", nullable=true)
*/
private $userDeleted;
/**
* #var \DateTime
*
* #ORM\Column(name="user_lastlogin", type="datetime", nullable=true)
*/
private $userLastlogin;
/**
* #var \DateTime
*
* #ORM\Column(name="user_confirmed", type="datetime", nullable=true)
*/
private $userConfirmed;
/**
* #var \DateTime
*
* #ORM\Column(name="user_locked", type="datetime", nullable=true)
*/
private $userLocked;
/**
* #var integer
*
* #ORM\Column(name="user_id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $userId;
/**
* #var \VolleyScout\VolleyScoutBundle\Entity\Roles
*
* #ORM\ManyToOne(targetEntity="VolleyScout\VolleyScoutBundle\Entity\Roles")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="role_id", referencedColumnName="role_id")
* })
*/
protected $role;
/**
* #var \Doctrine\Common\Collections\Collection
*
* #ORM\ManyToMany(targetEntity="VolleyScout\VolleyScoutBundle\Entity\Teams", inversedBy="user")
* #ORM\JoinTable(name="user_follows_teams",
* joinColumns={
* #ORM\JoinColumn(name="user_id", referencedColumnName="user_id")
* },
* inverseJoinColumns={
* #ORM\JoinColumn(name="team_id", referencedColumnName="team_id")
* }
* )
*/
private $team;
/**
* #var \Doctrine\Common\Collections\Collection
*
* #ORM\ManyToMany(targetEntity="VolleyScout\VolleyScoutBundle\Entity\Competitions", inversedBy="user")
* #ORM\JoinTable(name="user_follows_competitions",
* joinColumns={
* #ORM\JoinColumn(name="user_id", referencedColumnName="user_id")
* },
* inverseJoinColumns={
* #ORM\JoinColumn(name="competition_id", referencedColumnName="competition_id")
* }
* )
*/
private $competition;
private $plainPassword;
/**
* Constructor
*/
public function __construct()
{
$this->team = new \Doctrine\Common\Collections\ArrayCollection();
$this->competition = new \Doctrine\Common\Collections\ArrayCollection();
$this->salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
}
/**
* Set username
*
* #param string $username
* #return Users
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Get username
*
* #return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set password
*
* #param string $password
* #return Users
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* #return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set salt
*
* #param string $salt
* #return Users
*/
public function setSalt($salt)
{
$this->salt = $salt;
return $this;
}
/**
* Get salt
*
* #return string
*/
public function getSalt()
{
return $this->salt;
}
/**
* Set userFirstname
*
* #param string $userFirstname
* #return Users
*/
public function setUserFirstname($userFirstname)
{
$this->userFirstname = $userFirstname;
return $this;
}
/**
* Get userFirstname
*
* #return string
*/
public function getUserFirstname()
{
return $this->userFirstname;
}
/**
* Set userSurname
*
* #param string $userSurname
* #return Users
*/
public function setUserSurname($userSurname)
{
$this->userSurname = $userSurname;
return $this;
}
/**
* Get userSurname
*
* #return string
*/
public function getUserSurname()
{
return $this->userSurname;
}
/**
* Set userEmail
*
* #param string $userEmail
* #return Users
*/
public function setUserEmail($userEmail)
{
$this->userEmail = $userEmail;
return $this;
}
/**
* Get userEmail
*
* #return string
*/
public function getUserEmail()
{
return $this->userEmail;
}
/**
* Set userType
*
* #param string $userType
* #return Users
*/
public function setUserType($userType)
{
$this->userType = $userType;
return $this;
}
/**
* Get userType
*
* #return string
*/
public function getUserType()
{
return $this->userType;
}
/**
* Set userToken
*
* #param string $userToken
* #return Users
*/
public function setUserToken($userToken)
{
$this->userToken = $userToken;
return $this;
}
/**
* Get userToken
*
* #return string
*/
public function getUserToken()
{
return $this->userToken;
}
/**
* Set userCreated
*
* #param \DateTime $userCreated
* #return Users
*/
public function setUserCreated($userCreated)
{
$this->userCreated = $userCreated;
return $this;
}
/**
* Get userCreated
*
* #return \DateTime
*/
public function getUserCreated()
{
return $this->userCreated;
}
/**
* Set userModified
*
* #param \DateTime $userModified
* #return Users
*/
public function setUserModified($userModified)
{
$this->userModified = $userModified;
return $this;
}
/**
* Get userModified
*
* #return \DateTime
*/
public function getUserModified()
{
return $this->userModified;
}
/**
* Set userDeleted
*
* #param \DateTime $userDeleted
* #return Users
*/
public function setUserDeleted($userDeleted)
{
$this->userDeleted = $userDeleted;
return $this;
}
/**
* Get userDeleted
*
* #return \DateTime
*/
public function getUserDeleted()
{
return $this->userDeleted;
}
/**
* Set userLastlogin
*
* #param \DateTime $userLastlogin
* #return Users
*/
public function setUserLastlogin($userLastlogin)
{
$this->userLastlogin = $userLastlogin;
return $this;
}
/**
* Get userLastlogin
*
* #return \DateTime
*/
public function getUserLastlogin()
{
return $this->userLastlogin;
}
/**
* Set userConfirmed
*
* #param \DateTime $userConfirmed
* #return Users
*/
public function setUserConfirmed($userConfirmed)
{
$this->userConfirmed = $userConfirmed;
return $this;
}
/**
* Get userConfirmed
*
* #return \DateTime
*/
public function getUserConfirmed()
{
return $this->userConfirmed;
}
/**
* Set userLocked
*
* #param \DateTime $userLocked
* #return Users
*/
public function setUserLocked($userLocked)
{
$this->userLocked = $userLocked;
return $this;
}
/**
* Get userLocked
*
* #return \DateTime
*/
public function getUserLocked()
{
return $this->userLocked;
}
/**
* Get userId
*
* #return integer
*/
public function getUserId()
{
return $this->userId;
}
/**
* Set role
*
* #param \VolleyScout\VolleyScoutBundle\Entity\Roles $role
* #return Users
*/
public function setRoles(\VolleyScout\VolleyScoutBundle\Entity\Roles $role = null)
{
$this->role = $role;
return $this;
}
/**
* Get role
*
* #return \VolleyScout\VolleyScoutBundle\Entity\Roles
*/
public function getRoles()
{
return array($this->role->getRoleName());
}
/**
* Add team
*
* #param \VolleyScout\VolleyScoutBundle\Entity\Teams $team
* #return Users
*/
public function addTeam(\VolleyScout\VolleyScoutBundle\Entity\Teams $team)
{
$this->team[] = $team;
return $this;
}
/**
* Remove team
*
* #param \VolleyScout\VolleyScoutBundle\Entity\Teams $team
*/
public function removeTeam(\VolleyScout\VolleyScoutBundle\Entity\Teams $team)
{
$this->team->removeElement($team);
}
/**
* Get team
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getTeam()
{
return $this->team;
}
/**
* Add competition
*
* #param \VolleyScout\VolleyScoutBundle\Entity\Competitions $competition
* #return Users
*/
public function addCompetition(\VolleyScout\VolleyScoutBundle\Entity\Competitions $competition)
{
$this->competition[] = $competition;
return $this;
}
/**
* Remove competition
*
* #param \VolleyScout\VolleyScoutBundle\Entity\Competitions $competition
*/
public function removeCompetition(\VolleyScout\VolleyScoutBundle\Entity\Competitions $competition)
{
$this->competition->removeElement($competition);
}
/**
* Get competition
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getCompetition()
{
return $this->competition;
}
//**********************************
// HAD TO IMPLEMENT THESE BY MESELF
//**********************************//
private $player;
/**
* Get player
*
* #return \VolleyScout\VolleyScoutBundle\Entity\Players
*/
public function getPlayer() {
return $this->player;
}
/**
* Set player
*
* #param \VolleyScout\VolleyScoutBundle\Entity\Players $player
* #return Users
*/
public function setPlayer(\VolleyScout\VolleyScoutBundle\Entity\Players $player = null){
$this->player = $player;
return $this;
}
public function eraseCredentials()
{
$this->setPlainPassword(null);
}
public function getPlainPassword()
{
return $this->plainPassword;
}
public function setPlainPassword($plainPassword)
{
$this->plainPassword = $plainPassword;
}
/**
* Implementation of AdvancedUserInterface method
*
* #return boolean
*/
public function isAccountNonExpired()
{
return true;
}
/**
* Implementation of AdvancedUserInterface method
*
* #return boolean
*/
public function isAccountNonLocked()
{
return true;
}
/**
* Implementation of AdvancedUserInterface method
*
* #return boolean
*/
public function isCredentialsNonExpired()
{
return true;
}
/**
* Implementation of AdvancedUserInterface method
*
* #return boolean
*/
public function isEnabled()
{
// CHECK IF $this->confirmed is not null
if($this->userConfirmed != null){
return true;
}
}
}
The current logged in user is stored in the twig global variable app.user
{% if app.user.player.team %}
show button
{% else %}
not
{% endif %}
I firstly created the database and then generated the entities from it. After that I generated the getters and setters in the entities using:
php app/console doctrine:generate:entities DigitalManager
Later on I decided to create the association (One to Many) between the entities, so I added the respective commands in my Entities and what I got is this:
Party Entity:
<?php
namespace DigitalManager\Bundle\ERPBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Party
*
* #ORM\Table(name="party")
* #ORM\Entity
*/
class Party
{
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=45, nullable=true)
*/
private $name;
/**
* #ORM\ManyToOne(targetEntity="Account", inversedBy="parties")
* #ORM\JoinColumn(name="account_id", referencedColumnName="aid")
*/
public $account;
/**
* #var string
*
* #ORM\Column(name="address", type="string", length=45, nullable=true)
*/
private $address;
/**
* #var string
*
* #ORM\Column(name="phone_fax", type="string", length=45, nullable=true)
*/
private $phoneFax;
/**
* #var string
*
* #ORM\Column(name="fax", type="string", length=45, nullable=true)
*/
private $fax;
/**
* #var string
*
* #ORM\Column(name="email", type="string", length=45, nullable=true)
*/
private $email;
/**
* #var string
*
* #ORM\Column(name="mobile", type="string", length=45, nullable=true)
*/
private $mobile;
/**
* #var string
*
* #ORM\Column(name="country", type="string", length=45, nullable=true)
*/
private $country;
/**
* #var string
*
* #ORM\Column(name="city", type="string", length=45, nullable=true)
*/
private $city;
/**
* #var string
*
* #ORM\Column(name="phone_res", type="string", length=45, nullable=true)
*/
private $phoneRes;
/**
* #var string
*
* #ORM\Column(name="remarks", type="string", length=45, nullable=true)
*/
private $remarks;
/**
* #var boolean
*
* #ORM\Column(name="active", type="boolean", nullable=true)
*/
private $active;
/**
* #var integer
*
* #ORM\Column(name="limit", type="integer", nullable=true)
*/
private $limit;
/**
* #var integer
*
* #ORM\Column(name="term", type="integer", nullable=true)
*/
private $term;
/**
* #var string
*
* #ORM\Column(name="officer_id", type="string", length=45, nullable=true)
*/
private $officerId;
/**
* #var \DateTime
*
* #ORM\Column(name="date", type="datetime", nullable=true)
*/
private $date;
/**
* #var string
*
* #ORM\Column(name="cnic", type="string", length=45, nullable=true)
*/
private $cnic;
/**
* #var string
*
* #ORM\Column(name="ntn", type="string", length=45, nullable=true)
*/
private $ntn;
/**
* #var boolean
*
* #ORM\Column(name="L_O", type="boolean", nullable=true)
*/
private $lO;
/**
* #var string
*
* #ORM\Column(name="type", type="string", length=45, nullable=true)
*/
private $type;
/**
* #var integer
*
* #ORM\Column(name="acc_id", type="integer", nullable=true)
*/
private $accId;
/**
* #var integer
*
* #ORM\Column(name="party_id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $partyId;
/**
* Set name
*
* #param string $name
* #return Party
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set address
*
* #param string $address
* #return Party
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* Get address
*
* #return string
*/
public function getAddress()
{
return $this->address;
}
/**
* Set phoneFax
*
* #param string $phoneFax
* #return Party
*/
public function setPhoneFax($phoneFax)
{
$this->phoneFax = $phoneFax;
return $this;
}
/**
* Get phoneFax
*
* #return string
*/
public function getPhoneFax()
{
return $this->phoneFax;
}
/**
* Set fax
*
* #param string $fax
* #return Party
*/
public function setFax($fax)
{
$this->fax = $fax;
return $this;
}
/**
* Get fax
*
* #return string
*/
public function getFax()
{
return $this->fax;
}
/**
* Set email
*
* #param string $email
* #return Party
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* #return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set mobile
*
* #param string $mobile
* #return Party
*/
public function setMobile($mobile)
{
$this->mobile = $mobile;
return $this;
}
/**
* Get mobile
*
* #return string
*/
public function getMobile()
{
return $this->mobile;
}
/**
* Set country
*
* #param string $country
* #return Party
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* Get country
*
* #return string
*/
public function getCountry()
{
return $this->country;
}
/**
* Set city
*
* #param string $city
* #return Party
*/
public function setCity($city)
{
$this->city = $city;
return $this;
}
/**
* Get city
*
* #return string
*/
public function getCity()
{
return $this->city;
}
/**
* Set phoneRes
*
* #param string $phoneRes
* #return Party
*/
public function setPhoneRes($phoneRes)
{
$this->phoneRes = $phoneRes;
return $this;
}
/**
* Get phoneRes
*
* #return string
*/
public function getPhoneRes()
{
return $this->phoneRes;
}
/**
* Set remarks
*
* #param string $remarks
* #return Party
*/
public function setRemarks($remarks)
{
$this->remarks = $remarks;
return $this;
}
/**
* Get remarks
*
* #return string
*/
public function getRemarks()
{
return $this->remarks;
}
/**
* Set active
*
* #param boolean $active
* #return Party
*/
public function setActive($active)
{
$this->active = $active;
return $this;
}
/**
* Get active
*
* #return boolean
*/
public function getActive()
{
return $this->active;
}
/**
* Set limit
*
* #param integer $limit
* #return Party
*/
public function setLimit($limit)
{
$this->limit = $limit;
return $this;
}
/**
* Get limit
*
* #return integer
*/
public function getLimit()
{
return $this->limit;
}
/**
* Set term
*
* #param integer $term
* #return Party
*/
public function setTerm($term)
{
$this->term = $term;
return $this;
}
/**
* Get term
*
* #return integer
*/
public function getTerm()
{
return $this->term;
}
/**
* Set officerId
*
* #param string $officerId
* #return Party
*/
public function setOfficerId($officerId)
{
$this->officerId = $officerId;
return $this;
}
/**
* Get officerId
*
* #return string
*/
public function getOfficerId()
{
return $this->officerId;
}
/**
* Set date
*
* #param \DateTime $date
* #return Party
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* Get date
*
* #return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* Set cnic
*
* #param string $cnic
* #return Party
*/
public function setCnic($cnic)
{
$this->cnic = $cnic;
return $this;
}
/**
* Get cnic
*
* #return string
*/
public function getCnic()
{
return $this->cnic;
}
/**
* Set ntn
*
* #param string $ntn
* #return Party
*/
public function setNtn($ntn)
{
$this->ntn = $ntn;
return $this;
}
/**
* Get ntn
*
* #return string
*/
public function getNtn()
{
return $this->ntn;
}
/**
* Set lO
*
* #param boolean $lO
* #return Party
*/
public function setLO($lO)
{
$this->lO = $lO;
return $this;
}
/**
* Get lO
*
* #return boolean
*/
public function getLO()
{
return $this->lO;
}
/**
* Set type
*
* #param string $type
* #return Party
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* Get type
*
* #return string
*/
public function getType()
{
return $this->type;
}
/**
* Set accId
*
* #param integer $accId
* #return Party
*/
public function setAccId($accId)
{
$this->accId = $accId;
return $this;
}
/**
* Get accId
*
* #return integer
*/
public function getAccId()
{
return $this->accId;
}
/**
* Get partyId
*
* #return integer
*/
public function getPartyId()
{
return $this->partyId;
}
}
Account Entity
<?php
namespace DigitalManager\Bundle\ERPBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Account
*
* #ORM\Table(name="account")
* #ORM\Entity
*/
class Account
{
public function __construct()
{
parent::__construct();
// The line below must be here as a single category is to be mapped to many products, so an ArrayCollection is required instead of Array.
$this->parties = new ArrayCollection();
}
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=45, nullable=true)
*/
private $name;
// The metadata above the $products property of the Category object is less important, and simply tells
// Doctrine to look at the Product.category property to figure out how the relationship is mapped.
/**
* #ORM\OneToMany(targetEntity="Party", mappedBy="account")
*/
protected $parties;
/**
* #var string
*
* #ORM\Column(name="address", type="string", length=200, nullable=true)
*/
private $address;
/**
* #var string
*
* #ORM\Column(name="level1", type="string", length=45, nullable=true)
*/
private $level1;
/**
* #var string
*
* #ORM\Column(name="level2", type="string", length=45, nullable=true)
*/
private $level2;
/**
* #var string
*
* #ORM\Column(name="level3", type="string", length=45, nullable=true)
*/
private $level3;
/**
* #var string
*
* #ORM\Column(name="contact", type="string", length=45, nullable=true)
*/
private $contact;
/**
* #var integer
*
* #ORM\Column(name="aid", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $aid;
/**
* Set name
*
* #param string $name
* #return Account
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set address
*
* #param string $address
* #return Account
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* Get address
*
* #return string
*/
public function getAddress()
{
return $this->address;
}
/**
* Set level1
*
* #param string $level1
* #return Account
*/
public function setLevel1($level1)
{
$this->level1 = $level1;
return $this;
}
/**
* Get level1
*
* #return string
*/
public function getLevel1()
{
return $this->level1;
}
/**
* Set level2
*
* #param string $level2
* #return Account
*/
public function setLevel2($level2)
{
$this->level2 = $level2;
return $this;
}
/**
* Get level2
*
* #return string
*/
public function getLevel2()
{
return $this->level2;
}
/**
* Set level3
*
* #param string $level3
* #return Account
*/
public function setLevel3($level3)
{
$this->level3 = $level3;
return $this;
}
/**
* Get level3
*
* #return string
*/
public function getLevel3()
{
return $this->level3;
}
/**
* Set contact
*
* #param string $contact
* #return Account
*/
public function setContact($contact)
{
$this->contact = $contact;
return $this;
}
/**
* Get contact
*
* #return string
*/
public function getContact()
{
return $this->contact;
}
/**
* Get aid
*
* #return integer
*/
public function getAid()
{
return $this->aid;
}
}
After adding these association commands, I tried to generate the getters and setters for these using:
php app/console doctrine:generate:entities DigitalManager
But it doesn't seem to generate the getters and setters for these associated attributes. I have looked up the syntax through the Symfony2 documentation and it was the same for creating associations. Can anyone please tell me what's wrong here, why does it not generate the getters and setters, although the attributes are there?
It may be trying to read the information from somewhere else. Is there an XML file for the configuration of this entity under Bundle/Resources/config/doctrine/?
There are two process to generate an entity and create a database and so on process.
I think you can do this way
1. create a entity using command
php app/console doctrine:generate:entity
you provide shortcut name Like AcmeHelloBundle. After that it will ask you all the filed name of a table. step by step you create the table.
2. If you not create your database then set database configuration file and run this command
php app/console doctrine:database:create
3. After create the database you need to create the table depending on your entity that create in list 2 and run the folloing command like
php app/console doctrine:schema:update --force
4.Now you can create association with other entity. I just show here create entity but you need to create all entity that need for your project. After perfect association you need to run this command
php app/console doctrine:generate:entities DigitalManager
5. Finnaly you need to perform this command again
php app/console doctrine:schema:update --force
This may work fine.