LiipImagineBundle Picture does not appear after filtering - file-upload

I'm using the VichUploadBundle to upload images into my database, and would like to have the thumbnails of the images displayed on the website with LiipImage.
This is my config.yml with the files set up
//.....
vich_uploader:
db_driver: orm
twig: true
mappings:
product_image:
uri_prefix: /images/products
upload_destination: '%kernel.root_dir%/../web/images/products'
inject_on_load: false
delete_on_update: true
delete_on_remove: true
liip_imagine:
# configure resolvers
resolvers:
# setup the default resolver
default:
# use the default web path
web_path: ~
# your filter sets are defined here
filter_sets:
# use the default cache configuration
cache: ~
# the name of the "filter set"
my_thumb:
# adjust the image quality to 75%
quality: 75
# list of transformations to apply (the "filters")
filters:
# create a thumbnail: set size to 120x90 and use the "outbound" mode
# to crop the image when the size ratio of the input differs
thumbnail: { size: [120, 90], mode: outbound }
# create a 2px black border: center the thumbnail on a black background
# 4px larger to create a 2px border around the final image
background: { size: [124, 98], position: center, color: '#000000' }
Most of the code for liip is copied straight up from the documentation for testing.
This is my routing.yml
app:
resource: "#AppBundle/Controller/"
type: annotation
_liip_imagine:
resource: "#LiipImagineBundle/Resources/config/routing.xml
Finally I have the Image entity I want to upload.
It's as well a code copied from the official Vich documentation
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* #ORM\Entity
* #Vich\Uploadable
*/
class Image
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
// ..... other fields
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* #Vich\UploadableField(mapping="product_image", fileNameProperty="imageName")
*
* #var File
*/
protected $imageFile;
/**
* #ORM\Column(type="string", length=255)
*
* #var string
*/
protected $imageName;
/**
* #ORM\Column(type="string", length=100)
*
* #var string
*/
protected $imageTitle = null;
/**
* #ORM\Column(type="string", length=100)
*
* #var string
*/
protected $imageAuthor = null;
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* #param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
*
* #return Product
*/
public function setImageFile(File $image = null)
{
$this->imageFile = $image;
if ($image) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTimeImmutable();
}
return $this;
}
/**
* #return File|null
*/
public function getImageFile()
{
return $this->imageFile;
}
/**
* #param string $imageName
*
* #return Product
*/
public function setImageName($imageName)
{
$this->imageName = $imageName;
return $this;
}
/**
* #return string|null
*/
public function getImageName()
{
return $this->imageName;
}
/**
* #ORM\Column(type="datetime")
*
* #var \DateTime
*/
protected $updatedAt;
/**
* #return null
*/
public function getImageTitle()
{
return $this->imageTitle;
}
/**
* #param null $imageTitle
*/
public function setImageTitle($imageTitle)
{
$this->imageTitle = $imageTitle;
}
/**
* #return null
*/
public function getImageAuthor()
{
return $this->imageAuthor;
}
/**
* #param null $imageAuthor
*/
public function setImageAuthor($imageAuthor)
{
$this->imageAuthor = $imageAuthor;
}
}
In my controller I have the image table put into array with $em
$em = $this->getDoctrine()->getManager();
$list = $em->getRepository(Image::class)->findAll();
Which I later put into the view and (would want to) print them like so:
{% for l in list %}
<tr>
<td>
<img src="{{ asset('/images/products/'~l.imageName) | imagine_filter('my_thumb') }}" alt="{{ l.imageName }}">
</td>
<td>{{ l.imageTitle }}</td>
<td>{{ l.imageAuthor }}</td>
</tr>
{% endfor %}
Unfortunately the output looks like this:
Now the path is fine. The image works well without the imagine_filter(). Same effect would occur when using the Vich Assets.
When checked the path the image is linked under is:
http://localhost:8000/media/cache/resolve/my_thumb/images/products/hqdefault.jpg
The path to images is
web/images/products
Is there anyone who know what might be the issue?
Or to provide an alternative bundle for creating image thumbnails
All help would be amazing

FIXED: Enabling GD and filenames in php.ini and restating apache, afterwards clearing the cache fixed everything

Related

ApiPlatform: How to update instead of create a child entity that is not a #ApiResource nor a #ApiSubresource

I have a ThirdPartyEntity from a third party bundle that, using a ThirdPartyEntityTrait, I link to MyEntity in my project.
Now, as the ThirdPartyEntity is not set a ApiResource nor as an ApiSubresource and as I don't have any serializaton group set on MyEntity, when I get MyEntity from ApiPlatform, it returns me something like this:
{
"#id":"/api/my_entities/17",
"#type":"MyEntity",
"id":17,
"third_party_entity": {
"id":22,
"a_property":"some value"
}
}
BUT IF I PUT a changed value for a_property with this body:
{
"#id":"/api/my_entities/17",
"#type":"MyEntity",
"id":17,
"third_party_entity": {
"id":22,
"a_property":"some NEW value to update"
}
}
I get a new third_party_entity to be created and get this response:
{
"#id":"/api/my_entities/17",
"#type":"MyEntity",
"id":17,
"third_party_entity": {
"id":23,
"a_property":"some NEW value to update"
}
}
SO, HOW CAN I UPDATE third_party_entity instead of creating it each time?
HERE THERE ARE THE INVOLVED CLASSES AND TRAITS
/**
* #ORM\Table(name="app_my_entities")
* #ORM\Entity()
* #ApiResource()
*/
class MyEntity
{
// !!!!!!!!!!!!!!!!!!
// This is the trait I use to link MyEntity
// with the entity from the third-party bundle
// !!!!!!!!!!!!!!!!!!
use ThirdPartyEntityTrait;
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
...
}
And this is the ThirdPartyEntityTrait:
trait ThirdPartyEntityTrait
{
/**
* #ORM\OneToOne(targetEntity="Namespace\To\Bundle\Entity\ThirdPartyEntity", cascade={"all"})
* #ORM\JoinColumn(name="thirdPartyEntity", referencedColumnName="id")
*/
private $thirdPartyEntity;
/**
* #param thirdPartyEntity $thirdPartyEntity
*
* #return ThirdPartyEntity
*/
public function setThirdPartyEntity(thirdPartyEntity $thirdPartyEntity): ThirdPartyEntity
{
$this->thirdPartyEntity = $thirdPartyEntity;
/** #var ThirdPartyEntity $this */
return $this;
}
/**
* #return thirdPartyEntity
*/
public function getThirdPartyEntity(): ?thirdPartyEntity
{
return $this->thirdPartyEntity;
}
/**
* #return thirdPartyEntity
*/
public function removeThirdPartyEntity(): ?thirdPartyEntity
{
$thirdPartyEntity = $this->getThirdPartyEntity();
$this->thirdPartyEntity = null;
return $thirdPartyEntity;
}
}
As you can see, nothing more a property to save the relation and some accessors methods.
This is, instead, the linked Entity:
/**
* #ORM\Entity()
* #ORM\Table(name="third_party_entities")
*/
class ThirdPartyEntity
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #ORM\Column(name="aProperty", type="string", nullable=true)
*/
private $aProperty;
public function getId()
{
return $this->id;
}
public function getAProperty()
{
return $this->aProperty;
}
public function setAProperty($aProperty)
{
$this->aProperty = $aProperty;
return $this;
}
}
This question is cross-posted also on GitHub.
The solution was pretty simple: use another config method!
Practically, it is possible to mix configuration types and so, it is possible to use the annotations along with the yaml configuration.
Given this, it is sufficient to create a new config file in config/api_platform/third_party_entity.yaml.
In it put the configuration required to map the entity from the third party bundle:
resources:
App\Entity\MyEntity:
properties:
remote:
subresource:
resourceClass: 'Third\Party\Bundle\TheBundle\Entity\ThirdPartyEntity'
Third\Party\Bundle\TheBundle\Entity\ThirdPartyEntity:
This way it is possible to configure as subresource the entity from the third party bundle to which we don't have access with annotations.

Synfony 3 + Vich upload bundle - Failed to set metadata before uploading the file

My problem is to retrieve metadata before uploading the file.
My config file:
vich_uploader:
db_driver: orm
mappings:
media:
uri_prefix: /uploads/
upload_destination: '%kernel.root_dir%/../web/uploads'
inject_on_load: false
delete_on_update: true
delete_on_remove: true
I have an entity MEDIA :
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
**
* #ORM\Entity
* #Vich\Uploadable
*/
class Media
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
*
* #Vich\UploadableField(mapping="media", fileNameProperty="fileName",originalName="originalFileName")
*
* #var File
*/
private $file;
/**
* #ORM\Column(type="string", length=50)
*/
private $fileName;
/**
* #ORM\Column(type="string", length=255, nullable=false)
*/
private $originalFileName;
/**
* #ORM\Column(type="datetime")
*/
private $updatedAt;
/**
* #param File|\Symfony\Component\HttpFoundation\File\UploadedFile $file
*
* #return Media
*/
public function setFile(File $file = null)
{
$this->file = $file;
if ($file) {
$this->updatedAt = new \DateTimeImmutable();
}
return $this;
}
/**
* #return File|null
*/
public function getFile()
{
return $this->file;
}
/**
* #param string $fileName
*
* #return Media
*/
public function setFileName($fileName)
{
$this->fileName = $fileName;
return $this;
}
/**
* #return string|null
*/
public function getFileName()
{
return $this->fileName;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set updatedAt
*
* #param \DateTime $updatedAt
*
* #return Media
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* #return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Set originalFileName
*
* #param string $originalFileName
*
* #return Media
*/
public function setOriginalFileName($originalFileName)
{
$this->originalFileName = $originalFileName;
return $this;
}
/**
* Get originalFileName
*
* #return string
*/
public function getOriginalFileName()
{
return $this->originalFileName;
}
}
And here is my controller:
/**
* Creates a new media entity.
*
* #Route("/new", name="media_new")
* #Method({"GET", "POST"})
*
* #param Request $request
*
* #return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function newAction(Request $request)
{
$media = new Media();
$form = $this->createForm(MediaType::class, $media);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($media);
$em->flush();
return $this->redirectToRoute(
'media_list'
);
}
return $this->render(
'media/new.html.twig',
[
'media' => $media,
'form' => $form->createView(),
]
);
}
And my form:
<?php
/**
* Created by PhpStorm.
* User: rafael
* Date: 4/10/17
* Time: 12:46 PM
*/
namespace AppBundle\Form;
use AppBundle\Entity\Media;
use AppBundle\Entity\MediaDescriptionHelper;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class MediaType extends AbstractType
{
/**
* #param FormBuilderInterface $builder
* #param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('file', FileType::class)
->add('save', SubmitType::class, [
'attr' => ['class' => 'btn-primary btn-block']
]);
}
/**
* #param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(['data_class' => Media::class]);
}
}
The problem is with the mapping of these values :
#Vich\UploadableField(mapping="media", fileNameProperty="fileName",originalName="originalFileName")
When I submit my form these values are 'null' :
An exception occurred while executing 'INSERT INTO media (file_name, original_file_name, updated_at) VALUES (?, ?, ?)' with params ["get_image_resultat_sans_cache2.php.jpeg", null, "2017-04-12 10:11:56"]:
I have these issues with all parameters :
(https://github.com/dustin10/VichUploaderBundle/blob/master/Resources/doc/usage.md)
The UploadableField annotation has a few options. They are as follows:
mapping: required, the mapping name specified in the bundle configuration to use;
fileNameProperty: required, the property that will contain the name of the uploaded file;
size: the property that will contain the size in bytes of the uploaded file;
mimeType: the property that will contain the mime type of the uploaded file;
originalName: the property that will contain the origilal name of the uploaded file.
I don't see what I did wrong...
Here is my Media (entity) after the form is submitted :
Media {#403 ▼
-id: null
-file: UploadedFile {#15 ▼
-test: false
-originalName: "get_image_resultat_sans_cache2.php.jpeg"
-mimeType: "image/jpeg"
-size: 203751
-error: 0
path: "/tmp"
filename: "php9xsTdF"
basename: "php9xsTdF"
pathname: "/tmp/php9xsTdF"
extension: ""
realPath: "/tmp/php9xsTdF"
aTime: 2017-04-12 10:11:56
mTime: 2017-04-12 10:11:56
cTime: 2017-04-12 10:11:56
inode: 6160452
size: 203751
perms: 0100600
owner: 1000
group: 1000
type: "file"
writable: true
readable: true
executable: false
file: true
dir: false
link: false
}
-fileName: null
-originalFileName: null
It seems that's a problem when set metadata before uploading the file...
Thanks a lot in advance...
Which version of VichUploaderBundle do you use?
The documentation for the annotations refers to the dev-master one, while the stable one (1.5.3) doesn't support annotation for metadata out of the box.
You can see that Vich\UploaderBundle\Mapping\Annotation\UploadableField.php in the 1.5.3 version handles only annotations 'mapping' and 'fileNameProperty'.
While in the dev-master, it handles those and size, mimeType and originalName.
Same thing with Vich\UploaderBundle\Metadata\Driver\AnnotationDriver
If you want to achieve this in the 1.5.3 version you need to create an eventListener.
Here are the event triggered by Vich : https://github.com/dustin10/VichUploaderBundle/blob/1.5.3/Event/Events.php

A choice list based on database values in sonata

is it possible to add a choice list in configureformfields with choices values mapped from the database instead of configuring it manually like this :
->add('testfield', 'choice', array('choices' => array(
'1' => 'choice 1',
'2' => 'choice 2',)))
if the entity is correctly mapped then you can just use:
->add('testfield')
and Sonata admin will do the job.
Let's say you have a Product class linked to a Category class:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Product
*
* #ORM\Table(name="product")
*
*/
class Product
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="Category", inversedBy="products")
*/
protected $category;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set category
*
* #param Category $category
*
* #return Product
*/
public function setCategory(Category $category = null)
{
$this->category = $category;
return $this;
}
/**
* Get category
*
* #return Category
*/
public function getCategory()
{
return $this->category;
}
}
Simply using:
->add('category')
will provide a select form field with all the categories.
You can also use SONATA_TYPE_MODEL if you want something more advanced:
<?php
// src/AppBundle/Admin/ProductAdmin.php
class ProductAdmin extends AbstractAdmin
{
protected function configureFormFields(FormMapper $formMapper)
{
$imageFieldOptions = array(); // see available options below
$formMapper
->add('category', 'sonata_type_model', $imageFieldOptions)
;
}
}
The documentation is on this page: Form Types
Hope this helps!

How do I change default pagination attributes in Yii?

In my Yii project, I want the default pageSize for pagination to be fetched automatically, so I don't have to specify it in all the widgets that use pagination. But I can't seem to find a way to globally change the pagination class, without editing Yii source files. Is this possible?
Please create file on /components/WidgetFactory.php with below code.
<?php
/**
* Custom WidgetFactory class
* Provides two new events:
* - onBeforeCreateWidget
* - onAfterCreateWidget
*
* Allows for advanced global widget alteration, going a step further than CWidgetFactory's
* typical process which allows you to define default values for widgets.
*
*/
class WidgetFactory extends CWidgetFactory
{
/**
* Raised right BEFORE a widget is created.
* #param CEvent $event the event parameter
*/
public function onBeforeCreateWidget(CEvent $event)
{
$this->raiseEvent('onBeforeCreateWidget',$event);
}
/**
* Raised right AFTER a widget is created.
* #param CEvent $event the event parameter
*/
public function onAfterCreateWidget(CEvent $event)
{
$this->raiseEvent('onAfterCreateWidget',$event);
}
/**
* Creates a new widget based on the given class name and initial properties.
* #param CBaseController $owner the owner of the new widget
* #param string $className the class name of the widget. This can also be a path alias (e.g. system.web.widgets.COutputCache)
* #param array $properties the initial property values (name=>value) of the widget.
* #return CWidget the newly created widget whose properties have been initialized with the given values.
*/
public function createWidget($owner,$className,$properties=array())
{
if (! ($this->hasEventHandler('onBeforeCreateWidget') || $this->hasEventHandler('onAfterCreateWidget')))
return parent::createWidget($owner, $className, $properties);
$event=new WidgetEvent($this, $owner, $className, $properties);
if ($this->hasEventHandler('onBeforeCreateWidget'))
$this->raiseEvent('onBeforeCreateWidget', $event);
$event->widget=parent::createWidget($owner, $className, $properties);
if ($this->hasEventHandler('onAfterCreateWidget'))
$this->raiseEvent('onAfterCreateWidget', $event);
return $event->widget;
}
}
class WidgetEvent extends CEvent
{
/**
* #var CBaseController Owner of the new widget
*/
public $owner;
/**
* #var string Widget class name
*/
public $className;
/**
* #var CWidget The newly created widget
*/
public $widget;
/**
* Constructor.
* #param WidgetFactory $sender The WidgetFactory instance
* #param CBaseController $owner The owner of the new widget
* #param string $className The class name of the widget. This can also be a path alias.
* #param array $params The initial property values (name=>value) of the widget.
*/
public function __construct(WidgetFactory $sender, CBaseController $owner, $className, array $params=array())
{
parent::__construct($sender, $params);
$this->owner=$owner;
$this->className=$className;
}
}
And correct config/main.php like below.
return array(
// ...
'components'=>array(
// ...
'widgetFactory'=>array(
'class'=>'WidgetFactory',
'onAfterCreateWidget'=>function(WidgetEvent $event){
static $defaultPageSize=50; // YOUR_DEFAULT_PAGESIZE_HERE
$widget=$event->widget;
if ($widget instanceof CBaseListView) {
/** #var CBaseListView $widget */
if ($widget->dataProvider!==null && $widget->dataProvider->pagination!==false)
$widget->dataProvider->pagination->pageSize=$defaultPageSize;
}
},
),
// ...
),
);
Please notice default pageSize above on config code . I think it will solve your problem.

Unknown Entity namespace alias in symfony2

Hey I have two bundles in my symfony2 project. one is Bundle and the other one is PatentBundle.
My app/config/route.yml file is
MunichInnovationGroupPatentBundle:
resource: "#MunichInnovationGroupPatentBundle/Controller/"
type: annotation
prefix: /
defaults: { _controller: "MunichInnovationGroupPatentBundle:Default:index" }
MunichInnovationGroupBundle:
resource: "#MunichInnovationGroupBundle/Controller/"
type: annotation
prefix: /v1
defaults: { _controller: "MunichInnovationGroupBundle:Patent:index" }
login_check:
pattern: /login_check
logout:
pattern: /logout
inside my controller i have
<?php
namespace MunichInnovationGroup\PatentBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use JMS\SecurityExtraPatentBundle\Annotation\Secure;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Security\Core\SecurityContext;
use MunichInnovationGroup\PatentBundle\Entity\Log;
use MunichInnovationGroup\PatentBundle\Entity\UserPatent;
use MunichInnovationGroup\PatentBundle\Entity\PmPortfolios;
use MunichInnovationGroup\PatentBundle\Entity\UmUsers;
use MunichInnovationGroup\PatentBundle\Entity\PmPatentgroups;
use MunichInnovationGroup\PatentBundle\Form\PortfolioType;
use MunichInnovationGroup\PatentBundle\Util\SecurityHelper;
use Exception;
/**
* Portfolio controller.
* #Route("/portfolio")
*/
class PortfolioController extends Controller {
/**
* Index action.
*
* #Route("/", name="v2_pm_portfolio")
* #Template("MunichInnovationGroupPatentBundle:Portfolio:index.html.twig")
*/
public function indexAction(Request $request) {
$portfolios = $this->getDoctrine()
->getRepository('MunichInnovationGroupPatentBundle:PmPortfolios')
->findBy(array('user' => '$user_id'));
// rest of the method
}
Edit:
My Entity Class
<?php
namespace MunichInnovationGroup\PatentBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* MunichInnovationGroup\PatentBundle\Entity\PmPortfolios
*
* #ORM\Table(name="pm_portfolios")
* #ORM\Entity
*/
class PmPortfolios
{
/**
* #var string $id
*
* #ORM\Column(name="id", type="string", length=36, nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="UUID")
*/
private $id;
/**
* #var string $portfolioName
*
* #ORM\Column(name="portfolio_name", type="string", length=255, nullable=false)
*/
private $portfolioName;
/**
* #var text $description
*
* #ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* #var string $permalink
*
* #ORM\Column(name="permalink", type="string", length=255, nullable=false)
*/
private $permalink;
/**
* #var string $sharingCode
*
* #ORM\Column(name="sharing_code", type="string", length=255, nullable=false)
*/
private $sharingCode;
/**
* #var boolean $shared
*
* #ORM\Column(name="shared", type="boolean", nullable=false)
*/
private $shared;
/**
* #var integer $sharedPortfolioCalls
*
* #ORM\Column(name="shared_portfolio_calls", type="integer", nullable=true)
*/
private $sharedPortfolioCalls;
/**
* #var boolean $isDefault
*
* #ORM\Column(name="is_default", type="boolean", nullable=false)
*/
private $isDefault;
/**
* #var UmUsers
*
* #ORM\ManyToOne(targetEntity="UmUsers")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
* })
*/
private $user;
/**
* Get id
*
* #return string
*/
public function getId()
{
return $this->id;
}
/**
* Set portfolioName
*
* #param string $portfolioName
*/
public function setPortfolioName($portfolioName)
{
$this->portfolioName = $portfolioName;
}
/**
* Get portfolioName
*
* #return string
*/
public function getPortfolioName()
{
return $this->portfolioName;
}
/**
* Set description
*
* #param text $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* Get description
*
* #return text
*/
public function getDescription()
{
return $this->description;
}
/**
* Set permalink
*
* #param string $permalink
*/
public function setPermalink($permalink)
{
$this->permalink = $permalink;
}
/**
* Get permalink
*
* #return string
*/
public function getPermalink()
{
return $this->permalink;
}
/**
* Set sharingCode
*
* #param string $sharingCode
*/
public function setSharingCode($sharingCode)
{
$this->sharingCode = $sharingCode;
}
/**
* Get sharingCode
*
* #return string
*/
public function getSharingCode()
{
return $this->sharingCode;
}
/**
* Set shared
*
* #param boolean $shared
*/
public function setShared($shared)
{
$this->shared = $shared;
}
/**
* Get shared
*
* #return boolean
*/
public function getShared()
{
return $this->shared;
}
/**
* Set sharedPortfolioCalls
*
* #param integer $sharedPortfolioCalls
*/
public function setSharedPortfolioCalls($sharedPortfolioCalls)
{
$this->sharedPortfolioCalls = $sharedPortfolioCalls;
}
/**
* Get sharedPortfolioCalls
*
* #return integer
*/
public function getSharedPortfolioCalls()
{
return $this->sharedPortfolioCalls;
}
/**
* Set isDefault
*
* #param boolean $isDefault
*/
public function setIsDefault($isDefault)
{
$this->isDefault = $isDefault;
}
/**
* Get isDefault
*
* #return boolean
*/
public function getIsDefault()
{
return $this->isDefault;
}
/**
* Set user
*
* #param MunichInnovationGroup\PatentBundle\Entity\UmUsers $user
*/
public function setUser(\MunichInnovationGroup\PatentBundle\Entity\UmUsers $user)
{
$this->user = $user;
}
/**
* Get user
*
* #return MunichInnovationGroup\PatentBundle\Entity\UmUsers
*/
public function getUser()
{
return $this->user;
}
}
My bundle main class: MunichInnovationGroupPatentBundle.php
<?php
namespace MunichInnovationGroup\PatentBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class MunichInnovationGroupPatentBundle extends Bundle
{
}
when i try to load localhost/web/app_dev.php/portfolio
It says
Unknown Entity namespace alias 'MunichInnovationGroupPatentBundle'.
I am unable to figure out this error
please help me if anyone has any idea I googled it a lot :(
Thanks in advance
500 Internal Server Error - ORMException
Please, check your config.yml.
Reviewed in section mappings of entity_managers.
You should have something like MunichInnovationGroupPatentBundle: ~
That is:
doctrine:
orm:
entity_managers:
defaults:
mappings:
MunichInnovationGroupPatentBundle: ~
In my case I was missing namespace name in the security.yml under providers
I had:
entity: { class: AdministratorBundle:AdminUser }
and needed to have:
entity: { class: NamespaceAdministratorBundle:AdminUser }
If you use 2 or more entity managers -- you need to specify manager also
getManager('YourManager')
$repository =
$this->getDoctrine()
->getManager('YourManager')
->getRepository('YourBundle:YourEntity');
Check you bundle logical name (MunichInnovationGroupPatentBundle). Bundle logical name is name of main class of your bundle, e.g. JobsBundle
and provide your entity sourcecode.
Documentation here states you can use the string 'MunichInnovationGroupPatentBundle:PmPortfolios' as shortcut to 'MunichInnovationGroupPatentBundle\Entity\PmPortfolios' as long as your entity lives under the Entity namespace of your bundle.
Your bundle is MunichInnovationGroupBundle so instead of
->getRepository('MunichInnovationGroupPatentBundle:PmPortfolios')
use
->getRepository('MunichInnovationGroupPatentBundle\Entity\PmPortfolios')
Try being more explicit in your config.yml file by adding some fields:
orm:
...
mappings:
MunichInnovationGroupPatentBundle:
type: annotation
dir: "MunichInnovationGroupPatentBundle/Controller"
is_bundle: true
prefix: MunichInnovationGroup\PatentBundle
alias: MunichInnovationGroupPatentBundle
[more mappings..]
Please, check your config.yml + AppKernel.php
config.yml must be
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
or replace auto_mapping with
mappings:
StoreShopBundle: ~
for more, check this: https://stackoverflow.com/a/37652091/5809937
in AppKernel.php
don't forget to check if bundle is activated:
new MunichInnovationGroup\PatentBundle\MunichInnovationGroupPatentBundle(),
I had this when tried to use bandle name without core folder name. It was in config/security.yml
Folder structure in my case is the next src/Dp/UserBundle/....
I changed this
`providers:
main:
entity: { class: UserBundle:User, property: username }`
to this
`providers:
main:
entity: { class: DpUserBundle:User, property: username }`
So copy name of unknown Entity name and search each entries in project, check - they have to be with folder prefix (Dp in my case)
As at Symfony version 2.3.7, I used NameofCompanySomethingBundle:EntityRequired e.g. AcmeBlogBundle:User and it works.
auto-mapping: true (default) was used under orm: in config.yml.
This error will occur if you use multiple entity managers and you do not specify the entity manager in your controller function.
$em = $this->get('doctrine.orm.//your_entity_manager_name_here//_entity_manager');
$dql = "SELECT ...";
$query = $em->createQuery($dql);
this worked for me.
open your app\config.yml, must be
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
replace to
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
MunichInnovationGroupPatentBundle: ~