I am developing an application with symfony 2.8 with the bundle "FOSUSERBUNDLE", my problem is when I try to register a user, I can see the registration form, but when registering I throw the following error:
Unable to find the object manager associated with an entity of class
"Alienigena\ViviendaBundle\Entity\User".
I follow step by step the official tutorial of "FOSUSERBUNDLE", my USER class is:
namespace Alienigena\ViviendaBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="fos_user")
*/
class User extends BaseUser {
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
}
My problem originated because at the moment of mapping the bd with reverse engineering I did with the mapping in xml, I should have mapped it with annotations.
the solution consisted in eliminating the files with extension xml that were generated with the inverse engineering.
Thanks
Related
I'm using the SyliusResourceBundle as a standalone package for exposing data through an API.
When i request entities that have relationships with some other entities, i always get a full response with all the related entities properties included. This leads to heavy JSON responses, and too much data to download on the client side.
Typically, if my entity has a $user property like this :
/**
* #var User
*
* #ORM\ManyToOne(targetEntity="User", inversedBy="object")
*/
private $user;
I get all the user's stuff in the API response when i request the object : name, email, etc.
Is there a way to only get a list of properties/entities i need ? Like with an annotation or something ?
Thanks
For the record, SyliusResourceBundle uses JMSSeriliazerBundle, so it was just a matter of exclusion policy in the Resource Entity.
I just had to exclude all fields at the Entity level, and only expose the field i needed like this :
namespace AppBundle\Entity;
use JMS\Serializer\Annotation as JMS;
use Sylius\Component\Resource\Model\ResourceInterface;
use Doctrine\ORM\Mapping as ORM;
/**
*
* #JMS\ExclusionPolicy("all")
*/
class MyResource implements ResourceInterface
{
/**
* #ORM\ManyToOne(targetEntity="User", inversedBy="object")
*/
private $user;
/**
* #ORM\Column(type="string")
* #JMS\Expose()
*/
private $name;
}
See doc here.
I'm learning how to use FOSuserBundle and I've finished configuring it following the steps from the Symfony docs : Getting Started With FOSUserBundle
The problem is that when I want to update the database schema (doctrine:schema:update --force) I get :
Nothing to update - your database is already in sync with the current entity metadata.
But I think that it should update the user table.
This is my User class :
namespace Stage\AdminBundle\Bundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
}
So when I try to login :"Authentication request could not be processed due to a system problem.
" appears.
I don't know what should I do , please help me
thanks
finally i've found the solution , it's a mistake in the namespace
it's :: namespace Stage\AdminBundle\Bundle\Entity;
but it should be namespace Stage\AdminBundle\Entity;
I am a beginner in symfony 3. I currently have problems after installing FOSUserBundle. By creating my User entity I get this error: Error when access to app_dev.php
Here my entity User.php :
namespace SocialclockBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
/**
* #ORM\Table(name="user")
* #ORM\Entity(repositoryClass="SocialclockBundle\Repository\UserRepository")
*/
class User extends BaseUser
{
/**
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
}
And my UserRepository.php :
use Doctrine\ORM\EntityRepository;
namespace SocialclockBundle\Repository;
/**
* UserRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class UserRepository extends EntityRepository
{
}
Thank for your help !!!
florian
You need to put the use after the namespace
namespace SocialclockBundle\Repository;
use Doctrine\ORM\EntityRepository;
I have one table for which I am creating two entities.
One entity is used in my one core bundle which is used for many projects.
For new project I am creating new bundle and I want to add one more column in that entity.
Can anyone please guide me how can I override entity in other bundle.
You can extend your original User entity to something like this.
namespace XXXX;
use Doctrine\ORM\Mapping as ORM;
use XXXXX as BaseUser;
/**
* #ORM\Entity
* #ORM\Table(name="User")
*/
class User extends BaseUser
{
/**
* #var string
*
* #ORM\Column(name="newProperty", type="string", nullable=false)
*/
private $newProperty;
.....
.....
}
This will have all properties from your class BaseUser and you can have additional properties in this new class that you are trying to create. You can add set and get methods here too.
i have downloaded FOSUserBundle and configure it but i am facing the issue in updating the schema using following command
php app/console doctrine:schema:update
i am getting following exception for my existing database
[Doctrine\DBAL\Schema\SchemaException]
The table with name 'hub.tb_business_info' already exists.
tb_business_info is my existing table which was created by doctrine
so how would i create the User table in my existing database
Updated , here is my ORM defination
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
}