Вот код:
Контроллер
// Validation of user inputs
// New object with the ID of the existing one
$newFetcher = new Fetcher(
$request->input('id'),
$request->input('name'),
$request->input('vendorOID'),
$request->input('productOID'),
$request->input('versionOID'),
$request->input('updateOID')
);
// Calling repository to merge entities
$updatedFetcher = $this->q->update($newFetcher);
Репозиторий
public function update(Fetcher $fetcher)
{
$this->_em->merge($fetcher);
$this->_em->flush();
return $fetcher;
}
Образец класса сущности
public function __construct($id = 1, $name = "", $vendor_oid = null, $product_oid = null, $version_oid = null, $update_oid = null)
{
$this->id = $id;
$this->name = $name;
$this->vendor_oid = $vendor_oid;
$this->product_oid = $product_oid;
$this->version_oid = $version_oid;
$this->update_oid = $update_oid;
parent::setDateCreated();
parent::setTimestamp();
}
Примечание: все мои сущности выходят из суперкласса для общих полей, таких как ID, timestamp, date_created, которые я не хочу объявлять для каждой таблицы.
setTimestamp и setdatecreated устанавливают дату последнего обновления и дату создания на текущую метку времени:
Superclass
public function setTimestamp()
{
$this->timestamp = $this->getDateTime();
}
public function setDateCreated()
{
$this->date_created = $this->getDateTime();
}
public function getDateTime($tz = TIMEZONE)
{
return new DateTime("now", new DateTimeZone($tz));
}