title = "Brands" url = "/setup/brands" layout = "default" is_hidden = 0 == addJs('assets/js/setup/brands.js'); $this->addJs('assets/js/dataTablesSetup.js'); } function onAddBrand() { //get the values sent from ajax $code = $_POST['code']; $description = $_POST['description']; //wrap the mysql call into a try and catch so that we can catch any errors try { Db::insert("INSERT INTO custom_brands(code, description) VALUES(?, ?)",[$code,$description]); return 'ok'; } catch (\PDOException $e) { # do something or render a custom error page //\Flash::success('flash from ajax handler'); //return ['#flashDiv' => $this->renderPartial('flashMessage')]; return 'There was an error with adding the Brand to the database. Please make sure that the Code entered is not already in use.'; } } function onEditBrand() { //get the values sent from ajax $code = $_POST['code']; $description = $_POST['description']; //wrap the mysql call into a try and catch so that we can catch any errors try { Db::insert("UPDATE custom_brands SET description=:description WHERE code=:code",[$description,$code]); return 'ok'; } catch (\PDOException $e) { return 'There was an error while updating the Brand descritpion'; } } ?> ==