FosCommentBundle assetic exception to Symfony3 - php-7

I'm trying to use FosCommentBundle to Symfony3.
I complete all steps for installation with documentation of bundle.
I add AppKernel infos and created database, updated schemas and added Jquery3.
But when i try to check index.html.twig it gives following error.
There is no extension able to load the configuration for "assetic" (in C:\xampp\htdocs\blogbundle\app/config\config.yml). Looked for namespace "assetic", found "framework", "security", "twig", "monolog", "swiftmailer", "doctrine", "sensio_framework_extra", "fos_rest", "fos_comment", "jms_serializer", "debug", "web_profiler", "sensio_distribution", "web_server" in C:\xampp\htdocs\blogbundle\app/config\config.yml (which is being imported from "C:\xampp\htdocs\blogbundle\app/config/config_dev.yml").
my config.yml
fos_comment:
db_driver: orm
class:
model:
comment: AppBundle\Entity\Comment
thread: AppBundle\Entity\Thread
assetic:
bundles: [ "FOSCommentBundle" ]
routing.yml
app:
resource: '#AppBundle/Controller/'
type: annotation
fos_comment_api:
type: rest
resource: "#FOSCommentBundle/Resources/config/routing.yml"
prefix: /api
defaults: { _format: html }
Entities:
- Comment.php
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\CommentBundle\Entity\Comment as BaseComment;
/**
* #ORM\Entity
* #ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
*/
class Comment extends BaseComment
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* Thread of this comment
*
* #var Thread
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\Thread")
*/
protected $thread;
}
Thread.php
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\CommentBundle\Entity\Thread as BaseThread;
/**
* #ORM\Entity
* #ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
*/
class Thread extends BaseThread
{
/**
* #var string $id
*
* #ORM\Id
* #ORM\Column(type="string")
*/
protected $id;
}

All you have to do is to install the assetic bundle.
composer requires symfony/assetic-bundle
and then add this to registerBundles in appkernel
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
and add this to config.yml
assetic:
debug: '%kernel.debug%'
use_controller: '%kernel.debug%'
filters:
cssrewrite: ~

Related

Symfony 4 + JMS Serializer - Internal Server Error

I have a problem with serialization data.
I have two entities, which are connection relation.
These are my entities:
Task.php
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as JMS;
/**
* #ORM\Entity
*/
class Task
{
/**
*
* #var integer
*
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="IDENTITY")
*
*/
private $id;
/**
* #JMS\MaxDepth(1)
* #ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="task")
*
*/
private $user;
User.php
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="app_user")
*/
class User extends BaseUser
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #ORM\OneToMany(targetEntity="App\Entity\Task", mappedBy="user")
*/
private $task;
public function __construct()
{
I would like to create API, and I serialization my data with JMS. I get this error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
This is my controller:
public function getAllAction(): JsonResponse
{
$tasks = $this->taskService->getAll();
$serializer = SerializerBuilder::create()->build();
$data = $serializer->serialize($tasks, 'json',
SerializationContext::create()->enableMaxDepthChecks());
return new JsonResponse($data, 200, [], true);
}
Function getAll in my controller return data with table Task.
Please, help me with my problem. :)
Thanks, Friends.
I did not use JMS Serializer but i can suggest different solution like symfony serializer component.
public function getAllAction(SerializerInterface $serializer): JsonResponse
{
$data = $serializer->serialize($this->taskService->getAll(), 'json');
return new JsonResponse($data, 200, [], true);
}
Optional you can set serialization group to avoid circular reference error.
For each entity atribute that you want to serialize, set:
use Symfony\Component\Serializer\Annotation\Groups;
/**
* #ORM\Column(name="title", type="string", nullable=false, length=150)
* #Assert\Type("string")
* #Assert\NotBlank()
* #Groups({"group_name"})
*/
private $title;
/**
* #ORM\Column(name="description", type="string", nullable=true, length=255)
* #Assert\Type("string")
*/
private $description;
And then you serialize only this field with specific group:
$serializer->serialize($this->taskService->getAll(), 'json', ['groups' => ['group_name']])
Doc: https://symfony.com/doc/4.1/serializer.html#using-serialization-groups-annotations
PS. Action suffix isnt required now
https://symfony.com/doc/current/best_practices/controllers.html#controller-action-naming

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.

API Platform - Entity Translation, Doctrine Translatable

I'm trying to add KnpLabs Doctrine Behaviors - and precisely, the Translatable Behavior - on one of the entity in my API Platform project.
Here's what I've done so far :
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
use ApiPlatform\Core\Annotation\ApiResource;
/**
* #ORM\Entity(repositoryClass="App\Repository\ArticleRepository")
* #ApiResource
*/
class Article
{
use ORMBehaviors\Translatable\Translation,
ORMBehaviors\Timestampable\Timestampable
;
/**
* #ORM\Id
* #ORM\GeneratedValue
* #ORM\Column(type="integer")
*/
protected $id;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
}
And here's the Entity translation :
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Traits as CustomTraits;
/**
* #ORM\Entity(repositoryClass="App\Repository\ArticleTranslationRepository")
* #ApiResource
*/
class ArticleTranslation
{
use ORMBehaviors\Translatable\Translatable;
/**
* #var string
*
* #ORM\Column(name="someFieldToTranslate", type="string", length=255, nullable=true)
*/
private $someFieldToTranslate;
public function getSomeFieldToTranslate(){...}
public function setSomeFieldToTranslate($someFieldToTranslate){...}
}
Here's the basic "configuration" for getting Translatable Behavior working according to the doc.
Issues start when I try to update the DB schema : I got this error:
No identifier/primary key specified for Entity "App\Entity\ArticleTranslation". Every Entity must have an identifier/primary key in . (which is being imported from "/Sites/bookshop-api/config/routes/api_platform.yaml"). Make sure there is a
loader supporting the "api_platform" type.
However in Translatable Traits, there's already an ID and documentation precise that Translation Entity should only have fields we want to translate...
Anyway, I've put an ID to this ArtcleTranslation Entity to get rid of the error :
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Traits as CustomTraits;
/**
* #ORM\Entity(repositoryClass="App\Repository\ArticleTranslationRepository")
* #ApiResource
*/
class ArticleTranslation
{
use ORMBehaviors\Translatable\Translatable;
/**
* #ORM\Id
* #ORM\GeneratedValue
* #ORM\Column(type="integer")
*/
protected $id;
/**
* #var string
*
* #ORM\Column(name="content", type="string", length=255, nullable=true)
*/
private $content;
public function getContent(){...}
public function setContent($someContent){...}
}
From here, no error when I update the DB schema. Perfect !
Now I can take a look at the Swagger Documentation :
Everything looks fine ! But when I do take a look at the DB :
In Article table :
no "local" field
no "empty" field
In ArticleTranslation table :
no "translatable_id" field
no "currentLocal"
no "defaultLocal"
I guess it must be linked but in the swagger POST Tab, the model is different too.
article_translation model
I only tried /GET and /POST method on both entities, they're working (I can see it in DB) but no relation between the 2 of them.
I hope my post is not too long but I tried to be the more specific !
Thanks in advance
I did another answer as the first question was to resolve a mistake and not to explain how I integrated Knp Labs Doctrine Translations with Api Platform.
Summary :
We have an entity Article which has some fields translated inside an ArticleTranslation. We want to retrieve the entity through Api platform with its translations and we want to add or update translations through the api.
What I did :
1 - Article entity has a use ORMBehaviors\Translatable\Translatable. If we look inside of this trait, it has 2 attributes : $translations and $newTranslations. We need to expose these attributes inside the Article entity :
class Article {
use ORMBehaviors\Translatable\Translatable;
protected $translations;
protected $newTranslations;
}
Now we have a new attribute translations which is automatically filled from ArticleTranslation when we are getting some Article from the api
2 - Now we want to add/edit some translations : We need to fill the newTranslations attribute inside the Article when we are sending to the api:
"newTranslations": {
"en": {
"description": "Firstname"
},
"fr": {
"description": "Prénom"
}
}
Now we are receiving the new translations into the api but it's not persisted because we have to call the function mergeNewTranslations(). This function just take all translations inside the attribute $newTranslations and merge it with the $translations attribute in order to persist it.
3 - I created a new trait that I called TranslatableOverride. I imported it on directly on my Entity next to ORMBehaviors\Translatable\Translation:
trait TranslatableOverride
{
/**
* Set collection of new translations.
*
* #return ArrayCollection
*/
public function setNewTranslations($newTranslations)
{
if ($newTranslations) {
foreach ($newTranslations as $locale => $translations) {
foreach ($translations as $key => $value) {
$tr = $this->translate($locale);
$setter = 'set' . ucfirst($key);
if (method_exists($tr, $setter)) {
$tr->{$setter}($value);
}
}
}
$this->mergeNewTranslations();
}
}
}
I'm not sure if it's pretty but it works like a charm with api-platform.
I didn't think about getting only one translation at a time. For the moment, I retrieve my entities with the whole bunch of translations which is definitely not efficient. I will add an override for the getTranslations in my override trait I guess.
I think you did a mistake. You have an entity Article which should be the translatable and you want to translate some fields which will be the translations?
So you should make the opposite, put the use ORMBehaviors\Translatable\Translatableon the Article and the use ORMBehaviors\Translatable\Translation on the ArticleTranslation
The fix for your Article entity :
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
use ApiPlatform\Core\Annotation\ApiResource;
/**
* #ORM\Entity(repositoryClass="App\Repository\ArticleRepository")
* #ApiResource
*/
class Article
{
use ORMBehaviors\Translatable\Translatable,
ORMBehaviors\Timestampable\Timestampable
;
/**
* #ORM\Id
* #ORM\GeneratedValue
* #ORM\Column(type="integer")
*/
protected $id;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
}
and the fix for your ArticleTranslation entity :
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Traits as CustomTraits;
/**
* #ORM\Entity(repositoryClass="App\Repository\ArticleTranslationRepository")
* #ApiResource
*/
class ArticleTranslation
{
use ORMBehaviors\Translatable\Translation;
/**
* #var string
*
* #ORM\Column(name="someFieldToTranslate", type="string", length=255, nullable=true)
*/
private $someFieldToTranslate;
public function getSomeFieldToTranslate(){...}
public function setSomeFieldToTranslate($someFieldToTranslate){...}
}
Let me know if everything is alright now.

Inheritance Mapping and Many-To-One Relation

I made an abstract Upload class with 4 different children.
The classes UploadCompanyPic, UploadCompanyLogo and UploadUserPic are one-to-one relations, but the UploadPostFile has to be Many-to-one (one post has many uploaded files), I want to use alle the functions that are in the abstract class, but I can't get the Many-to-one relation to work.
This is what I have since now:
<?php
namespace AppBundle\Entity\Upload;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Mapping as ORM;
use AppBundle\Util\Registry;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* Abstract Class Upload
*
* #package AppBundle\Entity\Upload
*
* #ORM\MappedSuperclass()
* #ORM\Entity(repositoryClass="AppBundle\Repository\Upload\UploadRepository")
* #ORM\HasLifecycleCallbacks()
* #ORM\Table(name="upload", indexes={
* #ORM\Index(name="idx_cat_id", columns={"category","foreign_id"})
* }
* )
* #ORM\InheritanceType("SINGLE_TABLE")
* #ORM\DiscriminatorColumn(name="category", type="string")
* #ORM\DiscriminatorMap({"company-pic" = "UploadCompanyPic", "user-pic" = "UploadUserPic", "company-logo" = "UploadCompanyLogo", "post-file" = "UploadPostFile"})
*/
abstract class Upload
{
/**
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
* #ORM\Column(name="id", type="integer", length=255, nullable=false)
*/
protected $id;
protected $foreignId;
/**
some more code
* #return mixed
*/
public function getForeignId()
{
return $this->foreignId;
}
/**
* #param mixed $foreignId
*/
public function setForeignId($foreignId)
{
$this->foreignId = $foreignId;
}
UploadCompanyPic:
<?php
namespace AppBundle\Entity\Upload;
use Doctrine\ORM\Mapping as ORM;
use AppBundle\Entity\Upload\Upload as Upload;
/**
*
* #ORM\Entity
*
*/
class UploadCompanyPic extends Upload
{
protected $category="company-pic";
/**
* this is the foreign id of the mapped entity
* #ORM\Column(name="foreign_id", type="integer", length=255, nullable=false)
*/
protected $foreignId;
}
(Upload CompanyLogo and UploadUserPic look the same)
<?php
namespace AppBundle\Entity\Upload;
use AppBundle\Entity\Blog\Post;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use AppBundle\Entity\Upload\Upload as Upload;
/**
*
* #ORM\Entity
*
*/
class UploadPostFile extends Upload
{
protected $category="post-file";
/**
* ManyFiles have one Post
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\Blog\Post", inversedBy="files")
* #ORM\JoinColumn(name="foreign_id", referencedColumnName="id")
*/
protected $foreignId;
/**
* #return ArrayCollection
*/
public function getForeignId()
{
return $this->foreignId;
}
/**
* #param Post $foreignId
*/
public function setForeignId($foreignId)
{
$this->foreignId = $foreignId;
}
}
Any suggestions for me? Thanks!
One my colleagues found an answer:
/**
* Abstract Class Upload
*
* #package AppBundle\Entity\Upload
*
* #ORM\MappedSuperclass()
* #ORM\Entity(repositoryClass="AppBundle\Repository\Upload\UploadRepository")
* #ORM\HasLifecycleCallbacks()
* #ORM\Table(name="upload", indexes={
* #ORM\Index(name="idx_cat_id", columns={"category","foreign_id"})
* }
* )
* #ORM\InheritanceType("SINGLE_TABLE")
* #ORM\DiscriminatorColumn(name="category", type="string")
* #ORM\DiscriminatorMap({"company-pic" = "UploadCompanyPic", "user-pic" = "UploadUserPic", "company-logo" = "UploadCompanyLogo", "post-file" = "UploadPostFile", "partner-logo" = "UploadPartnerLogo"})
*/
abstract class Upload

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: ~