/** * @before _secure, _school */ public function addGuardian($scholar_user_id) { $usr = \User::first(array("id = ?" => $scholar_user_id), array("id")); if (!$usr) { self::redirect("/school"); } $this->setSEO(array("title" => "Parent Info | Student | School")); $view = $this->getActionView(); if (RequestMethods::post("action") == "saveParent") { $opts = array(); $opts["name"] = RequestMethods::post("name"); $opts["email"] = RequestMethods::post("email"); $opts["phone"] = RequestMethods::post("phone"); try { $user = $this->_createUser($opts); $loc = new Location(array("address" => RequestMethods::post("address"), "city" => RequestMethods::post("city"), "latitude" => "", "longitude" => "", "user_id" => $user->id)); $loc->save(); $guardian = new Guardian(array("user_id" => $user->id, "scholar_user_id" => $scholar_user_id, "relation" => RequestMethods::post("relation"), "occupation" => RequestMethods::post("occupation"), "qualification" => RequestMethods::post("qualification"), "location_id" => $loc->id)); $guardian->save(); $view->set("success", $guardian->relation . " info saved successfully!!"); } catch (\Exception $e) { $view->set("error", true); $view->set("message", $e->getMessage()); } } }