Add checking for duplicate ID. #298

This commit is contained in:
Korina Cordero 2020-01-17 08:11:09 +00:00
parent 2aed73b2d5
commit 91e495f251

View file

@ -134,7 +134,8 @@ class StaticContentController extends Controller
$row = new StaticContent();
// set and save values
$row->setID($req->request->get('id'));
$id = $req->request->get('id');
$row->setID($id);
$row->setContent($req->request->get('content'));
// validate
@ -143,6 +144,14 @@ class StaticContentController extends Controller
// initialize error list
$error_array = [];
// check for duplicate ID
$result = $em->getRepository(StaticContent::class)->find($id);
if ($result != null)
{
error_log($id);
$error_array['id'] = 'Duplicate ID exists.';
}
// add errors to list
foreach ($errors as $error) {
$error_array[$error->getPropertyPath()] = $error->getMessage();
@ -213,6 +222,14 @@ class StaticContentController extends Controller
// initialize error list
$error_array = [];
// check for duplicate ID
$result = $em->getRepository(StaticContent::class)->find($id);
if ($result != null)
{
error_log($id);
$error_array['id'] = 'Duplicate ID exists.';
}
// add errors to list
foreach ($errors as $error) {
$error_array[$error->getPropertyPath()] = $error->getMessage();