Symfony2 Session as Entity / Clearing old sessions without remember me - php

how i can use the $sessData, which is a blob?
Example entity
<?php
namespace Acme\DemoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Session
*
* #ORM\Table(name="sessions")
* #ORM\Entity
*/
class Session
{
/**
* #var string
*
* #ORM\Column(name="sess_id", type="string", length=128)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $sessId;
/**
* #var string
*
* #ORM\Column(name="sess_data", type="blob", length=65535, nullable=false)
*/
private $sessData;
/**
* #var integer
*
* #ORM\Column(name="sess_time", type="integer", nullable=false, options={"unsigned"=true})
*/
private $sessTime;
/**
* #var integer
*
* #ORM\Column(name="sess_lifetime", type="integer", nullable=false)
*/
private $sessLifetime;
}
Example command.
<?php
namespace Acme\UserBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Acme\UserBundle\Entity\Session;
/**
* Class ClearSessionsCommand
* #package Acme\UserBundle\Command
*/
class ClearSessionsCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('acme:clear:sessions')
->setDescription('Deletes old sessions from database')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
/** #var \Doctrine\Bundle\DoctrineBundle\Registry $doctrine */
$doctrine = $this->getContainer()->get('doctrine');
$repository = $doctrine->getManager()->getRepository('AcmeUserBundle:Session');
$sessions = $repository->findAll();
foreach($sessions as $session)
{
/** #var Session $session */
var_dump($session->getSessData());
}
}
}
And that's the output.
class Acme\UserBundle\Entity\Session#460 (4) {
private $sessId => string(26) "5v0as58i11vgikih7rb0b7fg41"
private $sessData => resource(419) of type (stream)
private $sessTime => int(1421508757)
private $sessLifetime => int(1440)
}
I'll hope you can help me.
I also tried to use "array", "simple_array" and "json_array".
But if i view the value in plain text i have a format like this.
_sf2_attributes|a:2:{s:18:"_csrf/authenticate";s:43:"esEvNzkJgkPN3JcgVWO71ArAHnoMxK_ChC1qdXT4bM4";s:14:"_security_main";s:691:"C:74:"Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken":603:{a:3:{i:0;N;i:1;s:4:"main";i:2;s:563:"a:4:{i:0;C:26:"Acme\UserBundle\Entity\User":227:{a:9:{i:0;s:88:"4T+akBl30pcGyIDl3MB64TT/o4izQZ/CA/JDHurok50o33g3L0bEgDYMj+itI5G6JWQmzH7gHTrDmLeE7I9yeQ==";i:1;s:31:"cljvnnze8jwo8ck4og8gcg08c4o0ww4";i:2;s:8:"max";i:3;s:8:"Max";i:4;b:0;i:5;b:0;i:6;b:0;i:7;b:1;i:8;i:1;}}i:1;b:1;i:2;a:2:{i:0;O:41:"Symfony\Component\Security\Core\Role\Role":1:{s:47:"
And i dont know whats this could be for a format.
If i remove _sf2_attributes| it might be serialized.
I would delete all sessions where older than one day and not logged in with remembered option.
Thanks in Advance!

Related

Symfony 3 / Doctrine many-to-one always returns just last addition- FOSUser/OAuth extended

I am working on a login page, where it should be possible to login with different socialnetwork logins (facebook, twitter, google, etc).
It should work like this: every user has the possibility to add the socialnetwork login that he/she wants, so I want to have it as an One User-> Many Socialnetworklogins relation.
What works: Data is stored in Database, but in the line
var_dump($user->getSocialnetworks());
I just get one Object, not all the ones that should be related to this user. I know that the function justATest adds just a socialnetworklogin to user 1, this was just a test.
<?php
namespace AppBundle\Entity\Registration;
use Doctrine\Common\Collections\ArrayCollection;
use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface;
use HWI\Bundle\OAuthBundle\Security\Core\User\FOSUBUserProvider as BaseClass;
use Symfony\Component\Security\Core\User\UserInterface;
class FOSUBUserProvider extends BaseClass
{
public function justATest(UserResponseInterface $response)
{
// get user_id and socialnetworkname from response
$userIdInSocialNetwork = $response->getUsername();
$socialnetwork = $response->getResourceOwner()->getName();
$login= new UserInSocialNetworks();
$login->setSocialIdentyfier($response->getEmail());
$login->setSocialNetworkSlug($socialnetwork);
$user = $this->userManager->findUserBy(array(
'id' => 1)
);
$login->setUserId($user);
$user->addSocialNetwork($login);
$this->userManager->updateUser($user);
$users= $this->userManager->findUsers();
var_dump($users);
var_dump($socialnetwork);
var_dump($user->getSocialnetworks());
die();
} }
The User Class:
<?php
/*
* This is the User class, depending on fos_userBundle
*/
namespace AppBundle\Entity\Registration;
use Doctrine\Common\Collections\ArrayCollection as ArrayCollection;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="user")
*/
class User extends BaseUser
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #ORM\OneToMany(targetEntity="UserInSocialNetworks", mappedBy="user_id", cascade={"persist", "remove"})
* #var ArrayCollection|null
*/
private $socialnetworks;
/**
* #var string
*
* #ORM\Column(name="family_name",type="string", length=255, nullable=true)
*/
private $familyName;
/**
* #var string
*
* #ORM\Column(name="given_name",type="string", length=255, nullable=true)
*/
private $givenName;
public function __construct()
{
parent::__construct();
$this->socialnetworks = new ArrayCollection();
}
/**
* #return string
*/
public function getFamilyName()
{
return $this->familyName;
}
/**
* #param string $familyName
*/
public function setFamilyName($familyName)
{
$this->familyName = $familyName;
}
/**
* #return string
*/
public function getGivenName()
{
return $this->givenName;
}
/**
* #param string $givenName
*/
public function setGivenName($givenName)
{
$this->givenName = $givenName;
}
/**
* #return ArrayCollection
*/
public function getSocialnetworks()
{
return $this->socialnetworks;
}
/**
* #param Collection UserInSocialNetworks
*/
public function setSocialnetworks($socialnetworks)
{
$this->socialnetworks = $socialnetworks;
}
/**
* #param UserInSocialNetwork
*/
public function addSocialNetwork($socialnetwork)
{
$this->getSocialnetworks()->add($socialnetwork);
}
}
The Class where Socialnetworks for Users are stored:
<?php
namespace AppBundle\Entity\Registration;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* UserInSocialNetworks
*
* #ORM\Table(name="user_in_social_networks")
* #ORM\Entity(repositoryClass="AppBundle\Repository\Registration\UserInSocialNetworksRepository")
*/
class UserInSocialNetworks
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="User", inversedBy="socialnetworks")
* #ORM\JoinColumn(name="user_id")
* #var User
*
*/
private $userId;
/**
* #var int
*
* #ORM\Column(name="social_network_slug", type="string", length=255, nullable=true)
*/
private $socialNetworkSlug;
/**
* #var string
*
* #ORM\Column(name="social_identifier", type="string", length=255, nullable=true)
*/
private $socialIdentyfier;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set userId
*
* #param integer $userId
*
* #return UserInSocialNetworks
*/
public function setUserId($userId)
{
$this->userId = $userId;
return $this;
}
/**
* Get userId
*
* #return int
*/
public function getUserId()
{
return $this->userId;
}
/**
* #return int
*/
public function getSocialNetworkSlug()
{
return $this->socialNetworkSlug;
}
/**
* #param int $socialNetworkSlug
*/
public function setSocialNetworkSlug($socialNetworkSlug)
{
$this->socialNetworkSlug = $socialNetworkSlug;
}
/**
* #return string
*/
public function getSocialIdentyfier()
{
return $this->socialIdentyfier;
}
/**
* #param string $socialIdentyfier
*/
public function setSocialIdentyfier($socialIdentyfier)
{
$this->socialIdentyfier = $socialIdentyfier;
}
}
This is what I get
object(Doctrine\ORM\PersistentCollection)[545]
private 'snapshot' =>
array (size=1) <------- just one
0 =>
object(AppBundle\Entity\Registration\UserInSocialNetworks)[336]
private 'id' => int 5 <---- I added already 5 line with my code to database
private 'userId' =>
object(AppBundle\Entity\Registration\User)[516]
...
private 'socialNetworkSlug' => string 'google' (length=6)
private 'socialIdentyfier' => string 'blablabla#googlemail.com' (length=24)
sorry, my fault,
the solution was to correct the relations:
class UserInSocialNetworks
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* Many Socialnetwork Logins have one User
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\Registration\User", inversedBy="socialnetworks")
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
*
*/
private $user;
and
class User extends BaseUser
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* One User can have many social networks
* #ORM\OneToMany(targetEntity="UserInSocialNetworks", mappedBy="user", cascade={"remove"})
*/
private $socialnetworks;

Extending adesigns EventEntity class

Hello guys i'm newbie on Symfony and making a web using sonata admin bundle. I wanted to add event on adesigns calendar bundle from sonata admin but when i extend EventEntity class and try to add new event, it gave me below error:
Type error: Argument 2 passed to
AppBundle\Entity\Schedule::__construct() must be an instance of
DateTime, none given, called in /path/to/project/vendor/sonata-project/doctrine-orm-admin-bundle/Model/ModelManager.php
on line 509
I know it causes type of DateTime, but i don't know how to solve it.
Here's the extended code:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use ADesigns\CalendarBundle\Entity\EventEntity;
/**
* Schedule
*
* #ORM\Table(name="schedule")
* #ORM\Entity(repositoryClass="AppBundle\Repository\ScheduleRepository")
*/
class Schedule extends EventEntity {
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var string
* #ORM\Column(name="title", type="string", length=255)
*/
protected $title;
/**
* #var string
* #ORM\Column(name="url", type="string", length=255, nullable=true)
*/
protected $url;
/**
* #var string
* #ORM\Column(name="bgColor", type="string", length=255)
*/
protected $bgColor;
/**
* #var string
* #ORM\Column(name="fgColor", type="string", length=255)
*/
protected $fgColor;
/**
* #var string
* #ORM\Column(name="cssClass", type="string", length=255, nullable=true)
*/
protected $cssClass;
/**
* #var bool
* #ORM\Column(name="allDay", type="boolean")
*/
protected $allDay;
/**
* #var DateTime
* #ORM\Column(name="startDatetime", type="datetime")
*/
protected $startDatetime;
/**
* #var DateTime
* #ORM\Column(name="endDatetime", type="datetime")
*/
protected $endDatetime;
public function __construct($title, \DateTime $startDatetime, \DateTime $endDatetime = null, $allDay = false, $hall) {
parent::__construct($title, $startDatetime, $endDatetime, $allDay);
$this->hall = $hall;
}
/**
* Get id
*
* #return int
*/
public function getId() {
return $this->id;
}
}
If you try to extend a Doctrine entity not designed for that you will encounter problems.
You should use an event listener or a subscriber class instead.

StofDoctrineExtensionsBundle checking the uniqueness of slug by the two fields

I use Knp\DoctrineBehaviors for Translation and StofDoctrineExtensionsBundle for Sluggable. How to make checking the uniqueness of slug by the sluggable and locale? I want to get the slug look like this:
for EN: /contacts
for PT: /pt/contacts
for PT (if duplicate): /pt/contacts-1
for ES: /es/contacts
But now, i have this database filter_node_translation
Entity\FilterNode.php:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
/**
* #ORM\Table(name="filter_node")
* #ORM\Entity()
*/
class FilterNode
{
use ORMBehaviors\Translatable\Translatable;
/**
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
* #ORM\Column(name="id", type="integer")
*/
protected $id;
/**
* #return mixed
*/
public function getId()
{
return $this->id;
}
}
FilterNodeTranslation:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* #ORM\Table(name="filter_node_translation")
* #ORM\Entity()
*/
class FilterNodeTranslation
{
use ORMBehaviors\Translatable\Translation;
/**
* #var string
*
* #ORM\Column(type="string", nullable=true)
*/
protected $sluggable;
/**
* #var string
*
* #Gedmo\Slug(fields={"sluggable"})
* #ORM\Column(type="string", nullable=true)
*/
protected $slug;
/**
* #return string
*/
public function getSluggable()
{
return $this->sluggable;
}
/**
* #param string $sluggable
*/
public function setSluggable($sluggable)
{
$this->sluggable = $sluggable;
}
}
I found solution. Gedmo sluggable have other configuration option "unique_base".
It looks like this:
class FilterNodeTranslation
{
/**
* #var string
*
* #Gedmo\Slug(updatable=true, unique=true, unique_base="locale", fields={"sluggable"})
* #ORM\Column(type="string")
*/
protected $slug;
}

symfony2 forms dynamically Generate Forms Based on user Data

I'm very new to symfony2 and i want to create a form. The values of fields should base on user data.
I have projects and users with a n:m-relation and now i want to embed a form in twig where I can assign users (multiple with one click) and projects. My class for user looks like:
// src/Pso/LogBundle/Entity/User.php
namespace Pso\LogBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use Doctrine\Common\Collections\ArrayCollection;
/**
* #ORM\Table(name="users", options={"collate"="utf8_general_ci", "charset"="utf8", "engine"="InnoDB"})
* #ORM\Entity(repositoryClass="Pso\LogBundle\Entity\UserRepository")
*/
class User implements AdvancedUserInterface, \Serializable
{
/**
* #ORM\Column(type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(type="string", length=25, unique=true)
*/
private $username;
/**
* #ORM\Column(type="string", length=32)
*/
private $salt;
/**
* #ORM\Column(type="string", length=250)
*/
private $password;
/**
* #ORM\Column(type="string", length=60, unique=true)
*/
private $email;
/**
* #ORM\Column(name="is_active", type="boolean")
*/
private $isActive;
/**
* #ORM\ManyToMany(targetEntity="Role", inversedBy="users")
* #ORM\JoinTable(name="user_role",
* joinColumns={#ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="role_id", referencedColumnName="id")}
* )
*
*/
private $roles;
The class for project looks like:
// src/Pso/ProjectBundle/Entity/Project.php
namespace Pso\ProjectBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* #ORM\Table(name="project", options={"collate"="utf8_general_ci", "charset"="utf8", "engine"="InnoDB"})
* #ORM\Entity(repositoryClass="Pso\ProjectBundle\Entity\ProjectRepository")
*/
class Project
{
/**
* #ORM\Column(name="id", type="integer")
* #ORM\Id()
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(type="string", length=255, unique=true, nullable=false)
*/
private $project_nr;
/**
* #ORM\ManyToOne(targetEntity="Pso\ProjectBundle\Entity\Mandator", inversedBy="projects")
* #ORM\JoinColumn(name="mandator_id", referencedColumnName="id")
*/
private $mandator;
/**
* #ORM\Column(type="string", length=80, nullable=false)
*/
private $project_name;
/**
* #ORM\Column(type="string", length=50)
*/
private $customer;
/**
* #ORM\Column(type="string", length=50)
*/
private $label;
/**
* #ORM\Column(type="date")
*/
private $shipping_date;
/**
* #ORM\Column(type="float")
*/
private $advance_payment;
/**
* #ORM\Column(type="integer", length=1)
*/
private $probability;
/**
* #ORM\Column(type="blob")
*/
private $special_demand;
/**
* #ORM\Column(type="string", length=4)
*/
private $currency;
/**
* #ORM\Column(type="integer", length=1, nullable=false)
*/
private $status;
/**
* #ORM\Column(type="string", length=100)
*/
private $contract_nr;
/**
* #ORM\Column(type="datetime", nullable=false)
*/
private $dbinsert;
/**
* #ORM\Column(type="datetime", nullable=false)
*/
private $dbupdate;
/**
* #ORM\ManyToMany(targetEntity="Pso\LogBundle\Entity\User", cascade={"persist", "remove"})
*/
private $users;
public function __construct() {
$this->user = new \Doctrine\Common\Collections\ArrayCollection();
}
My ProjectuserType looks like:
namespace Pso\ProjectBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormEvent;
use Doctrine\ORM\EntityRepository;
class ProjectuserType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('project','text')
;
$builder->addEventListener(
FormEvents::PRE_SET_DATA,
function (FormEvent $event) {
$form = $event->getForm();
$formOptions = array(
'class' => 'Pso\LogBundle\Entity\User',
'property' => 'username',
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('x')->FROM('PsoLogBundle:user', 'u')
->WHERE('u.id = :id')
->setParameter('id',5)
;
// or call a method on your repository that returns the query builder
// the $er is an instance of your UserRepository
// return $er->findnotsignedusers();
},
);
// or call a method on your repository that returns the query builder
// the $er is an instance of your UserRepository
// return $er->createOrderByFullNameQueryBuilder();
},
);
// create the field, this is similar the $builder->add()
// field name, field type, data, options
$form->add('user', 'entity', $formOptions);
}
);
}
public function getName()
{
return 'Projectuser';
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => null,
));
}
}
With the Type I oriented on the post and on documentation about chapter "How to dynamically Generate Forms Based on user Data"
With my Code I always get the error "Class Pso\ProjectBundle\Form\EntityRepository does not exist". I think I doesn't get right documentation. I don't want to get the data out of my ProjectRepository. This exists but the namespace is Pso\ProjectBundle\Form.
But my intention ist to get the data with the querybuilder in my EventListener. Every tipp would be appreciated.
Add this line in your ProjectuserType class : use Doctrine\ORM\EntityRepository
Hope it's helpful.
Best regards.

Doctrine2 Association Persistence

I've been playing around with Zend and Doctrine incorporated into it for the past week or so. I've gotten the hang of basic inserts and selects, and can also use DQL to select from joined tables. The problem I'm having is persisting associated entities. Error I'm getting is this: (path)htdocs\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\MappingException.php:96 with the message 'Class "" does not exist'.
My code is below...
Here is the main entity (the one on the "many" side)
namespace Project\Entity;
use Doctrine\ORM\Mapping as ORM;
use Zend\InputFilter\Factory as InputFactory;
/**
* ClientUser
*
* #ORM\Table()
* #ORM\Entity
*/
class ClientUser extends SystemUser
{
/**
* #var integer
*
* #ORM\OneToOne(targetEntity="SystemUser", cascade={"persist", "remove"})
* #ORM\JoinColumn(name="id", referencedColumnName="id")
*/
private $id;
/**
* #var integer
*
* #ORM\ManyToOne(targetEntity="Client", cascade={"persist", "remove"})
* #ORM\JoinColumn(name="client", referencedColumnName="id")
*/
private $client;
protected $_inputFilter;
//Other stuff here...
}
Here is the "Client" associated entity...
namespace Project\Entity;
use Doctrine\ORM\Mapping as ORM;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;
/**
* Client
*
* #ORM\Table()
* #ORM\Entity
*/
class Client implements InputFilterAwareInterface
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="client_name", type="string", length=255)
*/
private $clientName;
/**
* #var integer
*
* #ORM\Column(name="loggable_hours", type="integer")
*/
private $loggableHours;
/**
* #var float
*
* #ORM\Column(name="normal_rate", type="decimal", scale=2)
*/
private $normalRate;
/**
* #var float
*
* #ORM\Column(name="critical_rate", type="decimal", scale=2)
*/
private $criticalRate;
/**
* #var string
*
* #ORM\Column(name="start_date", type="string")
*/
private $startDate;
/**
* #var boolean
*
* #ORM\Column(name="enabled", type="boolean")
*/
private $enabled;
/**
* #var integer
*
* #ORM\Column(name="critical_hours", type="integer")
*/
private $criticalHours;
/**
*
* #var type
*/
protected $_inputFilter;
//Other stuff (getters,setters, etc)
}
The ClientUser has a one-to-one relationship with the following:
namespace Project\Entity;
use Doctrine\ORM\Mapping as ORM;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;
/**
* SystemUser
*
* #ORM\Table()
* #ORM\Entity
* #ORM\InheritanceType("JOINED")
* #ORM\DiscriminatorColumn(name="user_type", type="integer")
* #ORM\DiscriminatorMap({1 = "DeveloperUser", 2 = "ClientUser"})
*
*/
class SystemUser implements InputFilterAwareInterface {
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="username", type="string", length=100, unique=true)
*/
private $username;
/**
* #var string
*
* #ORM\Column(name="password", type="string", length=255)
*/
private $password;
/**
* #var string
*
* #ORM\Column(name="user_first_name", type="string", length=255)
*/
private $userFirstName;
/**
* #var string
*
* #ORM\Column(name="user_surname", type="string", length=255)
*/
private $userSurname;
/**
* #ORM\Column(type="string", length=32)
*/
private $salt;
/**
* #var \DateTime
*
* #ORM\Column(name="last_login", type="datetime")
*/
private $lastLogin = '0000-00-00 00:00:00';
/**
* #var bool
*
* #ORM\Column(name="enabled", type="boolean", options={"default" = 1})
*/
private $enabled = 1;
/**
* For the input filter...
*
* #var InputFilter
*/
protected $_inputFilter;
//The rest...
}
I have absolutely no idea what could be wrong here... Just for completeness, here is the controller "add" action...
public function addAction() {
//To add clients
$form = new ClientUserForm($this->getServiceLocator()
->get('Doctrine\ORM\EntityManager'));
$form->get('submit')->setValue('Add');
$request = $this->getRequest();
if ($request->isPost()) {
$clientUser = new ClientUser();
$form->setInputFilter($clientUser->getInputFilter());
$form->setData($request->getPost());
if ($form->isValid()) {
$clientUser->populate($form->getData());
/**
*This bottom line is where I get the exception!
*/
$this->getEntityManager()->persist($clientUser);
$this->getEntityManager()->flush();
//Redirect
return $this->redirect()->toRoute('client_user');
}
}
return array ('form' => $form);
}
Any help would be awesome! If I just knew which class "" is supposed to be, I'd probably be in a better place than I am now!
Thanks ladies and gents, you guys rock!
EDIT-
Forgot to add these 2 PHP warnings...
Warning: spl_object_hash() expects parameter 1 to be object, integer given in (path)\htdocs\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php on line 1588
Warning: get_class() expects parameter 1 to be object, integer given in (path)\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php on line 1596
Im not sure of what could be happening, but i find something that i dont understand. When you states the inheritance, you use:
* #ORM\DiscriminatorColumn(name="user_type", type="integer")
* #ORM\DiscriminatorMap({1 = "DeveloperUser", 2 = "ClientUser"})
but
there isnt a class called DeveloperUser
and also
are you sure that in the database, all user_type are just 1 or 2? (no null, not 0, etc)

Categories