我有一些问题.我是研究并尝试所有建议,但没有人工作.
我最终得到:
Argument 1 passed to Entity\User::addCategories() must be an instance of Entity\Category, string given,
i have manytomany relationship, user, user_category, and category
user
<?php
namespace Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
/**
* @Entity
* @Table(name="user")
*/
class User
{
/**
* @Id
* @Column(type="integer", nullable=false)
* @GeneratedValue(strategy="AUTO")
*/
public $id;
/**
* @Column(type="string", length=255, unique=true, nullable=false)
*/
public $name;
/**
* @ManyToMany(targetEntity="Entity\Category", inversedBy="user")
* @ORM\JoinTable(name="user_category")
*/
public $categories;
public function __construct() {
$this->category …Run Code Online (Sandbox Code Playgroud)