public function addAction() { $success = false; $code = Qrcode\Config::getByName($this->getParam("name")); if (!$code) { $code = new Qrcode\Config(); $code->setName($this->getParam("name")); $code->save(); $success = true; } $this->_helper->json(array("success" => $success, "id" => $code->getName())); }
public function addAction() { try { Qrcode\Config::getByName($this->getParam("name")); $alreadyExist = true; } catch (\Exception $e) { $alreadyExist = false; } if (!$alreadyExist) { $code = new Qrcode\Config(); $code->setName($this->getParam("name")); $code->save(); } $this->_helper->json(array("success" => !$alreadyExist, "id" => $code->getName())); }