Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9257719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:12:15+00:00 2026-06-18T12:12:15+00:00

i am getting the error when i try to flush the data, Warning: spl_object_hash()

  • 0

i am getting the error when i try to flush the data,

Warning: spl_object_hash() expects parameter 1 to be object

along with this message

Found entity of type on association Subject\Entity\Subject#user, but expecting Subject\Entity\User

now here is the action i am trying to implement

 public function addAction() {
    $form = new SubjectForm();
    $form->get('submit')->setAttribute('label', 'Add');
    $request = $this->getRequest();
    if (!$this->sessionVar) {
        $this->sessionVar = new SessionContainer('zftutorial');
        $userid = $this->sessionVar->offsetGet('userid');

        $form->get('user')->setAttribute('value', $userid);
    }
    $form->setData($request->getPost());

    if ($request->isPost()) {
        $subject = new Subject();
        $form->setInputFilter($subject->getInputFilter());
        if ($form->isValid()) {
            $subject->populate($form->getData());
            $this->getEntityManager()->persist($subject);
            $this->getEntityManager()->flush();
            return $this->redirect()->toRoute('subject');
        }
    }
    return array('form' => $form);
}

and this is my subject.php

namespace Subject\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;

/**
 *

 * @ORM\Entity

 * @ORM\Table(name="subject")

 * @property string $subjectname

 * @property int $user_id

 * @property int $id

 */
class Subject implements InputFilterAwareInterface {

protected $inputFilter;
/**

 * @ORM\Id

 * @ORM\Column(type="integer");

 * @ORM\GeneratedValue(strategy="AUTO")

 */
protected $id;
/**

 * @ORM\Column(type="string")

 */
protected $subjectname;
/**
 * @ORM\ManyToOne(targetEntity="Subject\Entity\User", inversedBy="subjects")
 * @var User|null
 */
private $user;

/** @return User|null */
public function getUser() {
    return $this->user;
}

/** @param User $user */
public function setUser(User $user) {
    if ($user === null || $user instanceof User) {
        $this->user = $user;
    } else {
        throw new InvalidArgumentException('$user must be instance of Entity\User or null!');
    }
}

/**

 * Magic getter to expose protected properties.

 *

 * @param string $property

 * @return mixed

 */
public function __get($property) {

    return $this->$property;
}

/**

 * Magic setter to save protected properties.

 *

 * @param string $property

 * @param mixed $value

 */
public function __set($property, $value) {

    $this->$property = $value;
}

/**

 * Convert the object to an array.

 *

 * @return array

 */
public function getArrayCopy() {

    return get_object_vars($this);
}

/**

 * Populate from an array.

 *

 * @param array $data

 */
public function populate($data = array()) {

    $this->id = $data['id'];

    $this->subjectname = $data['subjectname'];

    $this->user = $data['user_id'];
}



public function setInputFilter(InputFilterInterface $inputFilter) {

    throw new \Exception("Not used");
}

public function getInputFilter() {

    if (!$this->inputFilter) {
        $inputFilter = new InputFilter();
        $factory = new InputFactory();
        $inputFilter->add($factory->createInput(array(
                    'name' => 'id',

                    'filters' => array(
                        array('name' => 'Int'),
                    ),
                )));
        $inputFilter->add($factory->createInput(array(
                    'name' => 'subjectname',
                    'required' => true,
                    'filters' => array(
                        array('name' => 'StripTags'),
                        array('name' => 'StringTrim'),
                    ),
                    'validators' => array(
                        array(
                            'name' => 'StringLength',
                            'options' => array(
                                'encoding' => 'UTF-8',
                                'min' => 1,
                                'max' => 100,
                            ),
                        ),
                    ),
                )));



        $inputFilter->add($factory->createInput(array(
                    'name' => 'user_id',
                    'required' => true,
                    'filters' => array(
                        array('name' => 'Int'),
                    ),
                )));



        $this->inputFilter = $inputFilter;
    }



    return $this->inputFilter;
}

}

i am trying to implement oneToMany but i dont know what is wrong here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:12:16+00:00Added an answer on June 18, 2026 at 12:12 pm

    Ok found answer

    what i was doing was wrong i was doing this

    if ($request->isPost()) {
        $subject = new Subject();
        $form->setInputFilter($subject->getInputFilter());
        if ($form->isValid()) {
            $subject->populate($form->getData());
            $this->getEntityManager()->persist($subject);
            $this->getEntityManager()->flush();
            return $this->redirect()->toRoute('subject');
        }
    }
    

    Instead i had to first find the Relevant entity like this

     if ($request->isPost()) {
            $subject = new Subject();
    
    //following is the line  i was looking for
            $user = $this->getEntityManager()->getRepository('Subject\Entity\User')->find(array('id'=>$userid));
            $form->setInputFilter($subject->getInputFilter());
            if ($form->isValid()) {
                //$user->add
                //$subject->setUser($user);
                $subject->populate($form->getData());
                $subject->setUser($user);
                $this->getEntityManager()->persist($subject);
                $this->getEntityManager()->flush();
                return $this->redirect()->toRoute('subject');
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Getting this error when try to add an item to my repositories/context: Collection has
I am getting this error when I try to deploy my Web API project
I'm getting this error when I try run DB:Rake : ** Invoke db:migrate (first_time)
I keep getting this error when I try to commit a group of executed
i keep getting this error file already use by another program whenever i try
I'm getting folowwing error, when i try to save my Order Entity: Integrity constraint
getting error while try to start service
Update getting error when i try to call the method from Activity: SQLiteDatabase db
I am getting an error when i try to show a diff set of
I'm getting following error when I try to log onto phpMyAdmin. User * *

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.