PHP code example of renanbritz / doctrine-utils
1. Go to this page and download the library: Download renanbritz/doctrine-utils library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
renanbritz / doctrine-utils example snippets
use App\Entities\Person;
use RenanBritz\DoctrineUtils\Persistence;
class PersonController extends AbstractController
{
private $em;
private $persistence;
public function __construct()
{
$this->em = $this->getDoctrine()->getEntityManager();
$this->persistence = new Persistence($this->em);
}
/** Create a new person. */
public function store(Request $request)
{
$data = $request->all();
// Validation logic...
$this->persistence->persist(Person::class, $data);
// Domain/Business logic...
}
/** Update existing person. */
public function update(Request $request, int $personId)
{
$person = $this->em->getRepository(Person::class)->findOneById($personId);
if (!$person) {
// Return 404 error.
}
$data = $request->all();
// Validation logic...
$this->persistence->persist($person, $data);
// Domain/Business logic...
}
}