本文整理汇总了PHP中UserUtil::getUserById方法的典型用法代码示例。如果您正苦于以下问题:PHP UserUtil::getUserById方法的具体用法?PHP UserUtil::getUserById怎么用?PHP UserUtil::getUserById使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserUtil
的用法示例。
在下文中一共展示了UserUtil::getUserById方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: UserUtil
$UserUtil = new UserUtil($DB);
$BuildingUtil = new BuildingUtil($DB);
$user = new User(null, 'example', 'test@test.com');
$user->setPassword('a-password');
$user = $UserUtil->create($user);
if ($user != null) {
echo '<strong>UserUtil->create()</strong>';
echo '<pre>';
print_r($user);
echo '</pre>';
} else {
echo "A problem ocurred while trying to create the user";
}
if ($user != null) {
$id = $user->getId();
$user2 = $UserUtil->getUserById($id);
if ($user2 != null) {
echo '<strong>UserUtil->getUserById()</strong>';
echo '<pre>';
print_r($user2);
echo '</pre>';
} else {
echo "A problem ocurred while trying to get a user by ID";
}
}
if ($user != null) {
if ($UserUtil->removeUser($user)) {
echo '<strong>UserUtil->remove()</strong>';
echo '<br />OK';
} else {
echo "A problem ocurred while trying to remove the user from the database";
示例2: die
// Include class definitions before calling session_start()
require_once '../../server/classes/class.dbutil.php';
require_once '../../server/classes/class.users.php';
require_once '../../server/classes/class.buildings.php';
require_once '../../server/classes/class.operations.php';
require_once '../../server/classes/class.user.php';
require_once '../../server/config.php';
session_start();
if (count($_GET) != 0 && isset($_SESSION['userSession'])) {
// Check that all parameters have valid values
if (!is_numeric($_GET['x']) || !is_numeric($_GET['y']) || intval($_GET['x']) < 0 || intval($_GET['y']) < 0 || intval($_GET['x']) > GRID_X || intval($_GET['y']) > GRID_Y) {
die('ERROR');
}
$DB = new DBUtil(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
// DB name
if ($DB) {
$UserUtil = new UserUtil($DB);
$OperUtil = new OperationsUtil($DB);
$user = $UserUtil->getUserById($_SESSION['userSession']->getId());
// Is there anything in that coordinate?
$inst = $OperUtil->findBuildingInstanceByXY($user->getId(), $_GET['x'], $_GET['y']);
if ($inst) {
$OperUtil->removeInstance($inst);
die('OK');
} else {
die('ERROR');
}
}
} else {
die('ERROR');
}