Я новичок в symfony и следил за этим удивительным учебным пособием, чтобы настроить мои пакеты и сущности, используя командную строку, используя доктрину через консоль.Symfony Скрытые поля
http://symfony.com/blog/symfony2-getting-easier-interactive-generators
единственная проблема в том, что класс у меня есть установка имеет скрытые поля. например, дата создана и обновлена дата. Это только для моих записей, поэтому я вижу, что люди делали то, чего у них не было.
Единственная проблема заключается в том, что они отображаются на переднем конце, и я не знаю, как скрыть их, не переписывая созданный код и добавляя поля один за другим.
Вот функция в контроллере
public function createAction(Request $request)
{
$entity = new Client();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('client_show', array('id' => $entity->getId())));
}
return $this->render('AcmeClientMoodBundle:Client:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
/**
* Creates a form to create a Client entity.
*
* @param Client $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createCreateForm(Client $entity)
{
$form = $this->createForm(new ClientType(), $entity, array(
'action' => $this->generateUrl('client_create'),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
}
и вот сущность/класс
namespace Acme\ClientMoodBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* Client
*/
class Client
{
/**
* @var integer
*/
private $id;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $logo;
/**
* @var integer
*/
private $moodId;
/**
* @var integer
*/
private $projectManagerId;
/**
* @var \DateTime
*/
private $created;
/**
* @var \DateTime
*/
private $updated;
/**
* @var integer
*/
private $active;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Client
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set logo
*
* @param string $logo
* @return Client
*/
public function setLogo($logo)
{
$this->logo = $logo;
return $this;
}
/**
* Get logo
*
* @return string
*/
public function getLogo()
{
return $this->logo;
}
/**
* Set moodId
*
* @param integer $moodId
* @return Client
*/
public function setMoodId($moodId)
{
$this->moodId = $moodId;
return $this;
}
/**
* Get moodId
*
* @return integer
*/
public function getMoodId()
{
return $this->moodId;
}
/**
* Set projectManagerId
*
* @param integer $projectManagerId
* @return Client
*/
public function setProjectManagerId($projectManagerId)
{
$this->projectManagerId = $projectManagerId;
return $this;
}
/**
* Get projectManagerId
*
* @return integer
*/
public function getProjectManagerId()
{
return $this->projectManagerId;
}
/**
* Set created
*
* @param \DateTime $created
* @return Client
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* @return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated
*
* @param \DateTime $updated
* @return Client
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated
*
* @return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Set active
*
* @param integer $active
* @return Client
*/
public function setActive($active)
{
$this->active = $active;
return $this;
}
Как это лучший способ для достижения этой цели?
Woo, что так просто. Я люблю симфонию! спасибо за ваш быстрый ответ. – chris
Последнее, как передать переменную даты в базу данных. EG: следующее сообщение, мне нужно будет передать что-то вроде этого формата date date ('d-m-Y H: i: s'); 'INSERT INTO Client (имя, логотип, mood_id, project_manager_id, создано, обновлено, активно) VALUES (?,?,?,?,?,?,?)' С параметрами ["Test", "\/logo. jpg ", 1, 1, null, null, true]: – chris
Прежде чем продолжать сущность, вы должны использовать что-то вроде' $ entity-> setCreated (new \ Datetime ("now")); ' –