public function create($title, $content, $idAuthor) { $category = new Category($this->db); try { $category->setTitle($title); $category->setContent($content); $category->setIdAuthor($idAuthor); } catch (Exception $e) { $errors = $e->getMessage(); echo $errors; } if (!isset($err)) { $title = $this->db->quote($category->getTitle()); $content = $this->db->quote($category->getContent()); $idAuthor = $category->getIdAuthor(); $query = 'INSERT INTO category(title, content, idAuthor) VALUE (' . $title . ',' . $content . ',' . $idAuthor . ')'; } $res = $this->db->exec($query); if ($res) { $id = $this->db->lastInsertId(); if ($id) { return $this->findById($id); } else { throw new Exception('Database error'); } } else { throw new Exception($errors); } }
public function testSetGetTitle() { // Arrange $c = new Category(); $c->setTitle('drinks'); $expectedResult = 'drinks'; // Act $result = $c->getTitle(); // Assert $this->assertEquals($result, $expectedResult); }
function createAction(Request $request, Application $app) { if (null === ($user = $app['session']->get('user'))) { return $app->redirect('/login'); } $newCategory = new Category(); $newCategory->setTitle($request->get('title')); $newCategory->setSummary($request->get('summary')); $em = $app['orm.em']; $em->persist($newCategory); $em->flush(); return $app->redirect('/categoryAdmin'); }