尝试使用本手册http://www.ens.ro/2012/03/27/symfony2-jobeet-day-3-the-data-model/在Symfony 2上编写我的第一个应用程序 我的所有代码都像手动但我的命名空间和我得到了
属性"类别"也不是其中一种方法 " getCategory()"," category()"," isCategory()"," hasCategory()", " __得到()"在课堂上存在并具有公共访问权限 " JobeetBundle \实体\作业"
我认为在Form / JobType.php中生成了这个错误
class JobType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('type')
->add('company')
->add('logo')
->add('url')
->add('position')
->add('location')
->add('description')
->add('how_to_apply')
->add('token')
->add('is_public')
->add('is_activated')
->add('email')
->add('expires_at', DateType::Class)
->add('created_at',DateType::Class)
->add('updated_at',DateType::Class)
->add('category') ;
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'JobeetBundle\Entity\Job'
));
}
}
但我还没有在Entity \ Job中反对类别 它应该是实体\类别的引用,但仍然无法正常工作.. 请帮忙。以下是我的一些代码: 实体/ CAtegory.php:
?php
namespace JobeetBundle\Entity;
/**
* Category
*/
class Category
{
/**
* @var integer
*/
private $id;
/**
* @var string
*/
private $name;
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $jobs;
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $category_affiliates;
/**
* Constructor
*/
public function __construct()
{
$this->jobs = new \Doctrine\Common\Collections\ArrayCollection();
$this->category_affiliates = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* @return Category
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Add job
*
* @param \JobeetBundle\Entity\Job $job
*
* @return Category
*/
public function addJob(\JobeetBundle\Entity\Job $job)
{
$this->jobs[] = $job;
return $this;
}
/**
* Remove job
*
* @param \JobeetBundle\Entity\Job $job
*/
public function removeJob(\JobeetBundle\Entity\Job $job)
{
$this->jobs->removeElement($job);
}
/**
* Get jobs
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getJobs()
{
return $this->jobs;
}
/**
* Add categoryAffiliate
*
* @param \JobeetBundle\Entity\CategoryAffiliate $categoryAffiliate
*
* @return Category
*/
public function addCategoryAffiliate(\JobeetBundle\Entity\CategoryAffiliate $categoryAffiliate)
{
$this->category_affiliates[] = $categoryAffiliate;
return $this;
}
/**
* Remove categoryAffiliate
*
* @param \JobeetBundle\Entity\CategoryAffiliate $categoryAffiliate
*/
public function removeCategoryAffiliate(\JobeetBundle\Entity\CategoryAffiliate $categoryAffiliate)
{
$this->category_affiliates->removeElement($categoryAffiliate);
}
/**
* Get categoryAffiliates
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getCategoryAffiliates()
{
return $this->category_affiliates;
}
public function __toString()
{
return $this->getName();
}
}
实体/ Job.php
<?php
namespace JobeetBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Job
*/
class Job
{
/**
* @var string
*/
private $type;
/**
* @var string
*/
private $company;
/**
* @var string
*/
private $logo;
/**
* @var string
*/
private $url;
/**
* @var string
*/
private $position;
/**
* @var string
*/
private $location;
/**
* @var string
*/
private $description;
/**
* @var string
*/
private $howToApply;
/**
* @var string
*/
private $token;
/**
* @var boolean
*/
private $isPublic;
/**
* @var boolean
*/
private $isActivated;
/**
* @var string
*/
private $email;
/**
* @var \DateTime
*/
private $expiresAt;
/**
* @var \DateTime
*/
private $createdAt;
/**
* @var \DateTime
*/
private $updatedAt;
/**
* @var integer
*/
private $categoryId;
/**
* @var integer
*/
private $id;
/**
* Set type
*
* @param string $type
*
* @return Job
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* Get type
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Set company
*
* @param string $company
*
* @return Job
*/
public function setCompany($company)
{
$this->company = $company;
return $this;
}
/**
* Get company
*
* @return string
*/
public function getCompany()
{
return $this->company;
}
/**
* Set logo
*
* @param string $logo
*
* @return Job
*/
public function setLogo($logo)
{
$this->logo = $logo;
return $this;
}
/**
* Get logo
*
* @return string
*/
public function getLogo()
{
return $this->logo;
}
/**
* Set url
*
* @param string $url
*
* @return Job
*/
public function setUrl($url)
{
$this->url = $url;
return $this;
}
/**
* Get url
*
* @return string
*/
public function getUrl()
{
return $this->url;
}
/**
* Set position
*
* @param string $position
*
* @return Job
*/
public function setPosition($position)
{
$this->position = $position;
return $this;
}
/**
* Get position
*
* @return string
*/
public function getPosition()
{
return $this->position;
}
/**
* Set location
*
* @param string $location
*
* @return Job
*/
public function setLocation($location)
{
$this->location = $location;
return $this;
}
/**
* Get location
*
* @return string
*/
public function getLocation()
{
return $this->location;
}
/**
* Set description
*
* @param string $description
*
* @return Job
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set howToApply
*
* @param string $howToApply
*
* @return Job
*/
public function setHowToApply($howToApply)
{
$this->howToApply = $howToApply;
return $this;
}
/**
* Get howToApply
*
* @return string
*/
public function getHowToApply()
{
return $this->howToApply;
}
/**
* Set token
*
* @param string $token
*
* @return Job
*/
public function setToken($token)
{
$this->token = $token;
return $this;
}
/**
* Get token
*
* @return string
*/
public function getToken()
{
return $this->token;
}
/**
* Set isPublic
*
* @param boolean $isPublic
*
* @return Job
*/
public function setIsPublic($isPublic)
{
$this->isPublic = $isPublic;
return $this;
}
/**
* Get isPublic
*
* @return boolean
*/
public function getIsPublic()
{
return $this->isPublic;
}
/**
* Set isActivated
*
* @param boolean $isActivated
*
* @return Job
*/
public function setIsActivated($isActivated)
{
$this->isActivated = $isActivated;
return $this;
}
/**
* Get isActivated
*
* @return boolean
*/
public function getIsActivated()
{
return $this->isActivated;
}
/**
* Set email
*
* @param string $email
*
* @return Job
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set expiresAt
*
* @param \DateTime $expiresAt
*
* @return Job
*/
public function setExpiresAt($expiresAt)
{
$this->expiresAt = $expiresAt;
return $this;
}
/**
* Get expiresAt
*
* @return \DateTime
*/
public function getExpiresAt()
{
return $this->expiresAt;
}
/**
* Set createdAt
*
* @param \DateTime $createdAt
*
* @return Job
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = new \DateTime();
return $this;
}
/**
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set updatedAt
*
* @param \DateTime $updatedAt
*
* @return Job
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = new \DateTime();
return $this;
}
/**
* Get updatedAt
*
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Set categoryId
*
* @param integer $categoryId
*
* @return Job
*/
public function setCategoryId($categoryId)
{
$this->categoryId = $categoryId;
return $this;
}
/**
* Get categoryId
*
* @return integer
*/
public function getCategoryId()
{
return $this->categoryId;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
}
我可以展示其他代码,如果你需要它来让这个应用程序成真:: C:C:C请帮助。 THX