本文整理汇总了PHP中UserMapper::save方法的典型用法代码示例。如果您正苦于以下问题:PHP UserMapper::save方法的具体用法?PHP UserMapper::save怎么用?PHP UserMapper::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserMapper
的用法示例。
在下文中一共展示了UserMapper::save方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
$mapper = new UserMapper($this->adapter);
$user = new \Cactus\Entity(array('name' => 'Mr. Test', 'password' => "testingpassword", 'create_date' => date("Y-m-d H:i:s")));
list($id, $num) = $mapper->save($user);
// Dont do this for real, but I need to clean up for testing
$mapper->delete($user);
return $num === 1;
}
示例2: register
public function register()
{
$this->preguntasController->listados();
//$this->view->render("users", "register");
$user = new User();
if (isset($_POST["usuario"])) {
$user->setId($_POST["usuario"]);
$user->setNombre($_POST["nombre"]);
$user->setApellidos($_POST["apellidos"]);
$user->setCorreo($_POST["correo"]);
if (isset($_FILES['img'])) {
$img = $_FILES['img']['name'];
$ext = strrchr($img, '.');
$ruta = 'imagenes/user_' . $user->getId() . $ext;
if (move_uploaded_file($_FILES['img']['tmp_name'], $ruta)) {
$user->setImagen($user->getId() . $ext);
}
}
if ($_POST["pass"] == $_POST["repass"]) {
$pass = md5($_POST["pass"]);
$user->setPassword($pass);
} else {
$errors["pass"] = i18n("Passwords must be equal");
$this->view->setVariable("errors", $errors);
$this->view->render("users", "register");
return false;
}
try {
$user->checkIsValidForRegister();
if (!$this->userMapper->usernameExists($_POST["usuario"])) {
$this->userMapper->save($user);
$this->view->setFlash(i18n("Registered user"));
$this->view->redirect("users", "login");
} else {
$errors["usuario"] = i18n("User already exists");
$this->view->setVariable("errors", $errors);
}
} catch (ValidationException $ex) {
$errors = $ex->getErrors();
$this->view->setVariable("errors", $errors);
}
}
$this->view->render("users", "register");
}
示例3: saveUser
private function saveUser()
{
$email = $this->email;
$login = $this->login;
$password = md5($this->password);
//hash
$cookie = new Cookie();
$cookieGet = $cookie->getCookie($this->app);
$user = new User();
$user->login = $login;
$user->password = $password;
$user->email = $email;
$user->cookie = $cookieGet;
$Usermapper = new UserMapper($this->db);
$Usermapper->save($user);
$this->app->redirect('/TwigBlog');
}
示例4: registerProfesional
public function registerProfesional()
{
$jpop = new JuradoProfesional();
$currentuser = $this->view->getVariable("currentusername");
if (isset($_POST["usuario"])) {
$jpop->setId($_POST["usuario"]);
$jpop->setNombre($_POST["nombre"]);
$jpop->setEmail($_POST["correo"]);
$jpop->setProfesion($_POST["profesion"]);
$jpop->setOrganizador($currentuser);
$jpop->setTipo("juradoProfesional");
if ($_POST["pass"] == $_POST["repass"]) {
$jpop->setPassword($_POST["pass"]);
} else {
$errors["pass"] = "Las contraseñas tienen que ser iguales";
$this->view->setVariable("errors", $errors);
$this->view->render("users", "registerProfesional");
return false;
}
try {
$jpop->checkIsValidForCreate();
if (!$this->userMapper->usernameExists($_POST["usuario"])) {
$this->userMapper->save($jpop);
$this->view->setFlash("Usuario " . $jpop->getId() . " registrado.");
$this->view->redirect("concurso", "index");
} else {
$errors = array();
$errors["usuario"] = "El usuario ya existe";
$this->view->setVariable("errors", $errors);
}
} catch (ValidationException $ex) {
$errors = $ex->getErrors();
$this->view->setVariable("errors", $errors);
}
}
$this->view->setVariable("juradoProfesional", $jpop);
$this->view->render("users", "registerProfesional");
}
示例5: register
/**
* Action to register
*
* When called via GET, it shows the register form.
* When called via POST, it tries to add the user
* to the database.
*
* The expected HTTP parameters are:
* <ul>
* <li>login: The username (via HTTP POST)</li>
* <li>passwd: The password (via HTTP POST)</li>
* </ul>
*
* The views are:
* <ul>
* <li>users/register: If this action is reached via HTTP GET (via include)</li>
* <li>users/login: If login succeds (via redirect)</li>
* <li>users/register: If validation fails (via include). Includes these view variables:</li>
* <ul>
* <li>user: The current User instance, empty or being added
* (but not validated)</li>
* <li>errors: Array including validation errors</li>
* </ul>
* </ul>
*
* @return void
*/
public function register()
{
$user = new User();
if (isset($_POST["login"])) {
// reaching via HTTP Post...
$user = new User();
if ($_POST["tipo"] == "Jurado popular") {
$user->setLogin($_POST["login"]);
$user->setPasswd($_POST["passwd"]);
$user->setDni($_POST["dni"]);
$user->setName($_POST["name"]);
$user->setApellidos($_POST["apellidos"]);
$user->setMail($_POST["mail"]);
$user->setTelefono($_POST["telefono"]);
$user->settipo($_POST["tipo"]);
} else {
if ($_POST["tipo"] == "Establecimiento") {
$user = new Establecimiento();
$user->setLogin($_POST["login"]);
$user->setPasswd($_POST["passwd"]);
$user->setCif($_POST["cif"]);
$user->setNombre($_POST["nombreEstablecimiento"]);
$user->setDireccion($_POST["direccion"]);
$user->setHorario($_POST["horario"]);
$user->setPaginaWeb($_POST["paginaWeb"]);
$user->setTelefono($_POST["telefono"]);
$user->settipo($_POST["tipo"]);
}
}
try {
$user->checkIsValidForRegister();
// if it fails, ValidationException
// check if user exists in the database
if (!$this->userMapper->usernameExists($_POST["login"])) {
// save the User object into the database
$this->userMapper->save($user);
// POST-REDIRECT-GET
// Everything OK, we will redirect the user to the list of posts
// We want to see a message after redirection, so we establish
// a "flash" message (which is simply a Session variable) to be
// get in the view after redirection.
$this->view->setFlash("Username " . $user->getLogin() . " successfully added. Please login now");
// perform the redirection. More or less:
// header("Location: index.php?controller=users&action=login")
// die();
$this->view->redirect("users", "login");
} else {
$errors = array();
$errors["login"] = "Username already exists";
$this->view->setVariable("errors", $errors);
}
} catch (ValidationException $ex) {
// Get the errors array inside the exepction...
$errors = $ex->getErrors();
// And put it to the view as "errors" variable
$this->view->setVariable("errors", $errors);
}
}
// Put the User object visible to the view
$this->view->setVariable("user", $user);
// render the view (/view/users/register.php)
$this->view->render("users", "register");
}
示例6: array
$address = new \UserAddress();
$address->setField('city', 'Timisoara');
$address->setField('str', 'Borsec');
$addresses[] = $address;
$address = new \UserAddress();
$address->setField('city', 'New York');
$address->setField('str', 'Times Square');
$addresses[] = $address;
$address = new \UserAddress();
$address->setField('city', 'Munchen');
$address->setField('str', 'Leopold Strasse');
$addresses[] = $address;
$addresses->removeEntities(function ($entity) {
return $entity->getField('city') == 'Timisoara';
});
$user->setField('addresses', $addresses);
$personalInfo = new \UserPersonalInfo();
$personalInfo->setField('address', 'some fake address');
$personalInfo->setField('jobs', array('developer', 'cto'));
$credentials = new \UserCredentials();
$credentials->setField('email', 'geana.raul@gmail.com');
$credentials->setField('password', $authApi->hashPassword('password'));
$user->setField('personalInfo', $personalInfo);
$user->setField('credentials', $credentials);
$newUser = $user;
$return = \UserMapper::save($user);
$newUser->setField('parentId', $return);
$newUser->setField('_id', null);
$newReturn = \UserMapper::save($newUser);
$foundUser = \UserMapper::get($newReturn->getField('_id'));
print_r($foundUser->toArray());
示例7: saveUser
/**
* @param User $user
*/
public function saveUser(User $user)
{
$this->userMapper->save($user);
}