-2
オブジェクトを複製してデータベースに複製を保存したいが、自動シーケンスを取得できるようにIDをnullにリセットする必要があるという問題があるデータベースの番号。IDをnullに設定するオブジェクトの__cloneメソッドをオーバーロードする
私はDoctrineとSymfony2を利用しています。エンティティの__cloneメソッドを変更する必要があることを理解していますが、どのように挿入するかはわかりません。
私は基本的なクローンのアクションがあります。
public function cloneAction()
{
$object = $this->admin->getSubject();
if (!$object) {
throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
}
// Be careful, you may need to overload the __clone method of your object
// to set its id to null !
$clonedObject = clone $object;
$this->admin->create($clonedObject);
$this->addFlash('sonata_flash_success', 'Cloned successfully');
return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
}
のソナタのドキュメントには、私はそれをしなければならないが、私は前に__cloneで働いたことがない、と私はPHPを使用して新しい相対的なんだと言います。どんな助けでもよかったです。
こちらのドキュメントは次のとおりです。http://php.net/manual/en/language.oop5.cloning.php – Federkun