public function save() { $errors = []; $post = (object) $_POST; try { $this->client->setId((int) $post->id); $this->client->setName($post->name); $this->client->setMotherName($post->motherName); $this->client->setAddress($post->address); $this->client->setPhone($post->phone); $this->client->setCpfOrCnpj($post->cpfOrCnpj); $this->client->setEmail($post->email); $this->client->setCity($post->city); $this->client->setState($post->state); $this->client->setDistrict($post->district); $this->client->save(); } catch (\Exception $e) { error_log($e->getMessage()); $errors[] = 'Could not store the client in database'; } $action = $_GET['action']; if (count($errors) <= 0) { $redirector = new Redirector('Client', 'listAll'); $redirector->redirect(); } $this->{$action}($errors, $post); }
public function save() { $errors = []; $post = (object) $_POST; if ($post->password != $post->rpassword) { $errors[] = "Password don't match"; } try { $this->user->setId((int) $post->id); $this->user->setName($post->name); $this->user->setLogin($post->login); $this->user->setPassword($post->password); $this->user->setProfile($post->profile); $this->user->setEnable(isset($post->status) && $post->status == 1); $this->user->save(); } catch (\Exception $e) { error_log($e->getMessage()); $errors[] = 'Could not store the user in database'; } $action = $_GET['action']; if (count($errors) <= 0) { $redirector = new Redirector('User', 'listAll'); $redirector->redirect(); } $this->{$action}($errors, $post); }
public function __construct() { $session = new Session(); $redirector = new Redirector(DEFAULT_CONTROLLER, DEFAULT_ACTION); if (!$session->checkSession('user')) { $session->destroy(); $redirector->redirect(); } $this->user = unserialize($session->selectSession('user')); }