config.yml
vich_uploader:
db_driver: orm
mappings:
media_image:
uri_prefix: '%uploads_dir%'
upload_destination: '%kernel.root_dir%/../web/uploads/images'
namer: Vich\UploaderBundle\Naming\OrignameNamer
Entity:
/**
* Media
* #Vich\Uploadable
* #ORM\Table(name="medias")
* #ORM\Entity(repositoryClass="AppBundle\Repository\MediaRepository")
*/
class Media
{
use TimestampableEntity;
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(type="string", length=255, nullable=true)
* #var string
*/
private $imageName;
/**
* #Vich\UploadableField(mapping="media_image", fileNameProperty="imageName", mimeType="mimeType", size="size")
* #var File
*/
private $imageFile;
/**
* #var string
*
* #ORM\Column(name="mime_type", type="string", length=20, nullable=true)
*/
private $mimeType;
/**
* #var string
*
* #ORM\Column(name="size", type="integer", nullable=true)
*/
private $size;
When I enable namer, I am getting this error:
Any ideas why?
The (custom-)namer should be registered as a service and referred to by its service name.
You can see the default (long) configuration together with a list of namer services provided by VichUploaderBundle in the example below:
vich_uploader:
# [..]
mappings:
product_image_file:
# [..]
namer:
# one of: vich_uploader.namer_{uniqid,origname,property,hash}
service: vich_uploader.namer_origname
For reference, here are all namer services as listed by the command bin/console debug:container:
vich_uploader.namer_base64 Vich\UploaderBundle\Naming\Base64Namer
vich_uploader.namer_directory_property Vich\UploaderBundle\Naming\PropertyDirectoryNamer
vich_uploader.namer_hash Vich\UploaderBundle\Naming\HashNamer
vich_uploader.namer_origname Vich\UploaderBundle\Naming\OrignameNamer
vich_uploader.namer_property Vich\UploaderBundle\Naming\PropertyNamer
vich_uploader.namer_uniqid Vich\UploaderBundle\Naming\niqidNamer
Related
I am using fosElastica for populate at elasticsearch. I have a two entity, that entities relationship together.
But I couldn't populate and show category name in products index. How can I to do?
Entity/AirportCodes.php
/**
* #var string $AirportCode
*
* #ORM\Column(name="AirportCode", type="string", length=3)
* #ORM\OneToOne(targetEntity="XXXBundle\Entity\AirportCodesTrans")
* #ORM\JoinColumn(name="AirportCode", referencedColumnName="airport_code", nullable=false)
*/
private $airportCode;
Services.yml
example-connect:
properties:
AirportCode: { type: text, analyzer: autocomplete }
AirportSlug: ~
CountryCode: ~
CityCode: ~
persistence:
driver: orm
model: XXXBundle\Entity\AirportCodes
identifier: AirportCode
provider: ~
finder: ~
Entity/AirportCodesTrans
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string $AirportCode
*
* #ORM\Column(name="airport_code", type="string", length=3)
*/
private $airportCode;
/**
* #var string $lang
*
* #ORM\Column(name="lang", type="string", length=3)
*/
private $lang;
/**
* #var string $name
*
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
I am using Skipper ORM to design/generate entities - everything exports fine - then I do:
app/console doctrine:database:drop --force
app/console doctrine:database:create
app/console doctrine:schema:update --force
app/console doctrine:generate:entities --no-backup MyNamespace/MyBundle
I am receiving an error/exception:
[Doctrine\DBAL\Schema\SchemaException]
There is no column with name 'alternateId' on table 'inventory'.
What gives? The entity in question certainly does have the field:
<?php
namespace Company\DistributionBundle\Entity;
use Doctrine\ORM\Mapping AS ORM;
/**
* #ORM\Entity(repositoryClass="Company\DistributionBundle\Repository\InventoryRepository")
* #ORM\Table(
* name="inventory",
* indexes={#ORM\Index(name="ALTID", columns={"alternateId"})},
* uniqueConstraints={
* #ORM\UniqueConstraint(name="PKID", columns={"id"}),
* #ORM\UniqueConstraint(name="FINDID", columns={"partNumber","partDescription"})
* }
* )
*/
class Inventory
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(type="integer", nullable=false)
*/
private $alternateId;
/**
* #ORM\Column(type="integer", nullable=false)
*/
private $unitOftMeasure;
/**
* #ORM\Column(type="integer", nullable=false)
*/
private $minimumQuantity;
/**
* #ORM\Column(type="integer", nullable=false)
*/
private $maximumQuantity;
/**
* #ORM\Column(type="decimal", nullable=false)
*/
private $maximumCycles;
/**
* #ORM\Column(type="decimal", nullable=false, precision=10, scale=4)
*/
private $maximumTime;
/**
* #ORM\Column(type="decimal", nullable=false, precision=10, scale=2)
*/
private $listPrice;
/**
* #ORM\Column(type="date", nullable=false)
*/
private $datePrice;
/**
* #ORM\Column(type="string", length=50, nullable=false)
*/
private $partNumber;
/**
* #ORM\Column(type="string", length=50, nullable=false)
*/
private $partDescription;
/**
* #ORM\Column(type="text", length=255, nullable=true)
*/
private $partNotes;
/**
* #ORM\OneToOne(targetEntity="Company\DistributionBundle\Entity\Application", inversedBy="inventory")
* #ORM\JoinColumn(name="application_id", referencedColumnName="id", nullable=false, unique=true)
*/
private $application;
/**
* #ORM\OneToOne(targetEntity="Company\DistributionBundle\Entity\Category", inversedBy="inventory")
* #ORM\JoinColumn(name="category_id", referencedColumnName="id", nullable=false, unique=true)
*/
private $category;
/**
* #ORM\OneToOne(targetEntity="Company\DistributionBundle\Entity\Manufacturer", inversedBy="inventory")
* #ORM\JoinColumn(name="manufacturer_id", referencedColumnName="id", nullable=false, unique=true)
*/
private $manufacturer;
/**
* #ORM\ManyToMany(targetEntity="Company\DistributionBundle\Entity\InventoryOptions", mappedBy="inventory")
*/
private $inventoryOptions;
}
Try using the doctrine migrations bundle for two reasons:
It helps you manage your production database and all the versions of it. You can check any version any time
It Beautifully creates 'sql migrations' for you. Which you can use to (run migrations) to make changes in database.
Also, it understand your entities, read the annotations and creates the required files.
Go ahead and explore it.
I need to configure the payum bundle in order to let clients process paypal payments.
I just followed the getting started official recomendations, but need to configure something more, I guess (maybe I am missing to configure the storage for PaymentDetails somewhere).
my config files are as follows:
**app/config.yml**
doctrine:
orm:
auto_generate_proxy_classes: true
entity_managers:
default:
mappings:
WebsiteDeviceBundle: ~
WebsiteOnePageBundle: ~
payum:
is_bundle: false
type: xml
dir: %kernel.root_dir%/../vendor/payum/payum/src/Payum/Core/Bridge/Doctrine/Resources/mapping
prefix: Payum\Core\Model
payum:
security:
token_storage:
Website\Bundle\DeviceBundle\Entity\PaymentToken: { doctrine: orm }
storages:
Website\Bundle\DeviceBundle\Entity\PaymentDetails: { doctrine: orm }
contexts:
express_euro:
paypal_express_checkout_nvp:
username: ''
password: ''
signature: ''
sandbox: true
this is my controller action to start the payment process
public function prepareAction(){
$paymentName = 'express_euro';
$storage = $this->get('payum')->getStorage('Website\DeviceBundle\Entity\PaymentDetails');
$order = $storage->createModel();
$order->setNumber(uniqid());
$order->setCurrencyCode('EUR');
$order->setTotalAmount($this->view['user']->money);
$order->setDescrizione('annual account subscription');
$order->setUser($this->view['user']->getId());
$order->setCreatedAt(new \DateTime());
$order->setClientEmail($this->view['user']->getEmail());
$storage->updateModel($order);
$captureToken = $this->get('payum.security.token_storage')->createCaptureToken(
$paymentName,
$order,
'done' // the route to redirect after capture;
);
return $this->redirect($captureToken->getTargetUrl());
}
and this is PaymentDetails class
<?php
namespace Website\Bundle\DeviceBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Payum\Core\Model\ArrayObject;
/**
* PaymentDetails
*
* #ORM\Table(name="PaymentDetails", indexes={#ORM\Index(name="user", columns={"user"})})
* #ORM\Entity(repositoryClass="Website\Bundle\DeviceBundle\Entity\PaymentsDetailsRepository")
*/
class PaymentDetails extends ArrayObject
{
/**
* #var string
*
* #ORM\Column(name="currency_code", type="string", length=255, nullable=false)
*/
private $currencyCode;
/**
* #var string
*
* #ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* #var \DateTime
*
* #ORM\Column(name="created_at", type="datetime", nullable=true)
*/
private $createdAt;
/**
* #var integer
*
* #ORM\Column(name="number", type="integer", nullable=false)
*/
private $number;
/**
* #var integer
*
* #ORM\Column(name="total_amount", type="integer", nullable=false)
*/
private $totalAmount;
/**
* #var string
*
* #ORM\Column(name="client_email", type="text", nullable=false)
*/
private $clientEmail;
/**
* #var integer
*
* #ORM\Column(name="id", type="bigint")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var \Website\Bundle\DeviceBundle\Entity\Users
*
* #ORM\ManyToOne(targetEntity="Website\Bundle\DeviceBundle\Entity\Users")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="user", referencedColumnName="id")
* })
*/
private $user;
and the error it comes when I GET the doneAction() url, is this
A storage for model Website\DeviceBundle\Entity\PaymentDetails was not registered. There are storages for next models: Website\Bundle\DeviceBundle\Entity\PaymentDetails.
any helps or suggestions?
thank you in advance
just changed this line
$storage = $this->get('payum')->getStorage('Website\DeviceBundle\Entity\PaymentDetails');
into
$storage = $this->get('payum')->getStorage('Website\Bundle\DeviceBundle\Entity\PaymentDetails');
and now it works.
I making a RESTful app with Symfony and FOSRestBundle. FOSRestBundle uses JMS Serializer to serialize data to json format. I have everything working with one little issue.
This is my Entity class
/**
* Post
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="Tomalo\AdminBundle\Entity\PostRepository")
* #ExclusionPolicy("none")
*/
class Post
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="content", type="text")
* #Assert\NotBlank()
*/
private $content;
/**
* #var float
*
* #ORM\Column(name="lat", type="float")
* #Assert\NotBlank()
*/
private $lat;
/**
* #var float
*
* #ORM\Column(name="lon", type="float")
* #Assert\NotBlank()
*/
private $lon;
/**
* #var \DateTime
*
* #ORM\Column(name="date", type="datetime")
*/
private $date;
/**
* #var string
*
* #ORM\Column(name="sign", type="string", length=50, nullable=true)
* #Expose
*/
private $sign;
/**
* #var integer
*
* #ORM\Column(name="status", type="integer")
*/
private $status=0;
/**
* #var integer
*
* #ORM\Column(name="points", type="integer")
*/
private $points=0;
/**
* #var string
*
* #ORM\Column(name="uuid", type="string", length=43)
* #Assert\NotBlank()
* #Exclude
*/
private $uuid;
private $owner;
//get/set method continue
and this is json I get:
{
"id": 5,
"content": "zxcvzxcvzxc",
"lat": 37.422005,
"lon": -122.084095,
"date": "2013-05-20T05:06:57+0100",
"status": 0,
"points": 0,
"owner": 0
}
In my entity $uuid is the only property haveing #Exclude annotation and is not there as expected but there is $sign property missing as well. As You see I put #Expose annotation to $sign but changed nothing. I tried using #ExclusionPolicy("all") and expose all except for uuid but I'm getting
Warning: json_encode(): recursion detected in E:\workspace\htdocs\tomalo\vendor\jms\serializer\src\JMS\Serializer\JsonSerializationVisitor.php line 29
I found some information as it is some php bug
any idea what is wrong and how to fix it?
You can serialize nulls as empty strings. Guess it help you a bit
$context = new SerializationContext();
$context->setSerializeNull(true);
$objectData = $serializer->serialize($object, 'json', $context);
For FOSRestBundle you can define it in settings
fos_rest:
view:
serialize_null: true
forgottenbas'es solution for FOSRestBundle didn't work for me. I have found a solution here https://github.com/FriendsOfSymfony/FOSRestBundle/pull/480
Use serializer section in your config, not view:
fos_rest:
serializer:
serialize_null: true
I have an entity called Upload and another one called Shop
The Shop can have only one Upload
class Shop
{
/**
* #var integer $id
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var Upload
*
* #ORM\OneToOne(targetEntity="Vendor\SystemBundle\Entity\Upload",cascade={"all"})
*/
private $myfile;
}
class Upload
{
/**
* #var integer $id
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string $name
*
* #ORM\Column(name="name", type="string")
*/
private $name;
/**
* #var string $path
*
* #ORM\Column(name="path", type="string")
*/
private $path;
/**
* #var string $uniqId
*
* #ORM\Column(name="uniqId", type="string", nullable=true)
*/
private $uniqId;
/**
* #var integer $size
*
* #ORM\Column(name="size", type="integer", nullable=true)
*/
private $size;
/**
* #var string $extension
*
* #ORM\Column(name="extension", type="string", nullable=true)
*/
private $extension;
}
! Because my class Shop is generated automatically, i can't specify the relation into my class Upload
Is there a way to remove the relation and delete the corresponding item.
For now, if i want to remove my entity Upload, it says i have a Foreign Key contraint (which is normal), so I am trying to remove the relation directly from Shop, but I don't know how to do
You generated it using the php app/console doctrine:generate:entity command?
If you want to remove the relation remove the part
/**
* #var Upload
*
* #ORM\OneToOne(targetEntity="Vendor\SystemBundle\Entity\Upload",cascade={"all"})
*/
private $myfile;
and then do
php app/console doctrine:generate:entities Your\Entity\Path\
php app/console doctrine:schema:update --force
So it re-creates the getters and setters and delete the constrain from the db