本文整理汇总了PHP中UserMapper::findByName方法的典型用法代码示例。如果您正苦于以下问题:PHP UserMapper::findByName方法的具体用法?PHP UserMapper::findByName怎么用?PHP UserMapper::findByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserMapper
的用法示例。
在下文中一共展示了UserMapper::findByName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: login
/**
* Tries to log the user using the username and password received in the post.
*/
function login()
{
$text = $this->icfTemplating->getText();
$username = $_POST["username"];
$password = $_POST["password"];
// No data for login...
if ($username == "") {
$this->controllerData["loginfailed"] = $text["incorrectinput"];
$this->show_view();
return;
}
// Get the user
$userMapper = new UserMapper();
$user = $userMapper->findByName($username);
if ($user != null) {
// The user exists, validate the password
$login = $user->login($password);
if ($login) {
// User logged in !! register it in the session
$session = new Session($user);
// Redirect to home
$this->show_home_view();
return;
}
}
// The login has failed, send the error
$this->controllerData["loginfailed"] = $text["loginfailed"];
// .. and display the data that the user gave to us
$this->controllerData["username"] = $username;
$this->controllerData["password"] = $password;
$this->show_view();
}
示例2: json_encode
<?php
$rootPass = dirname(__FILE__) . '/../../';
require_once $rootPass . 'lib/db/dbfunctions.php';
require_once $rootPass . 'lib/db/Model/User.php';
require_once $rootPass . 'lib/db/Mapper/UserMapper.php';
$pdo = getPDO($argv[2]);
$umapper = new UserMapper($pdo);
$user = $umapper->findByName($argv[1]);
$userArray = (array) $user;
foreach ($userArray as $value) {
// オブジェクトのネストを解消(だいぶ汚いので後で直す)
$userArray = $value;
break;
}
header("Content-Type: application/json; charset=utf-8");
echo json_encode((array) $userArray);
// echo json_encode($result);
示例3: testFindByName
public function testFindByName()
{
$userName = "forFindByNameUser";
$userName2 = "otherUser";
$user = getUserInstance($userName);
$user2 = getUserInstance($userName2);
$umapper = new UserMapper(self::$pdo);
$umapper->insert($user);
$umapper->insert($user2);
$newUser = $umapper->findByName($user->user_name);
$this->assertEquals($newUser->user_name, $userName);
}