本文整理匯總了PHP中UserMapper::insert方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserMapper::insert方法的具體用法?PHP UserMapper::insert怎麽用?PHP UserMapper::insert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類UserMapper
的用法示例。
在下文中一共展示了UserMapper::insert方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: UserMapper
$userMapper = new UserMapper($db);
$user = $userMapper->findById($_SESSION['userID']);
$tpl_engine->__set_filetpl('main.html', array('user' => $user->getUserName()));
$tpl_engine->render();
} else {
(new ReportingFramework())->report(['condition' => "failure", 'message' => "This is a restricted area! Please login"]);
}
});
$rout_r->map('GET', '/api/user/register/', function () {
global $GLOBALS;
$query = $GLOBALS['query'];
if (isset($query["username"]) || isset($query["name"]) || isset($query["password"]) || isset($query["email"]) || isset($query["key"])) {
$user = new User(null, $query["username"], $query["name"], $query["password"], false, $query["email"], $query["key"]);
$db = new MySqlDAO();
$userMapper = new UserMapper($db);
$userMapper->insert($user);
die("User registration was successful!");
} else {
die("Input all params!");
}
});
$rout_r->map('GET', '/api/user/login/', function () {
session_start();
global $GLOBALS;
$query = $GLOBALS['query'];
if (isset($query["username"]) || isset($query["password"])) {
$db = new MySqlDAO();
$userMapper = new UserMapper($db);
$user = $userMapper->findByUserName($query["username"]);
$userID = $user->getID();
if (count($user) != 0 && isset($userID) && $userID != null) {
示例2: 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);
}
示例3: sizeof
$userMapper = new UserMapper($db);
$articleMapper = new ArticleMapper($db);
//get user by username
$user = $userMapper->findOne(array("conditions" => array('username = ? ', "john doe")));
echo "Username: " . $user->username;
echo "<br />Articles of this user:<br />";
foreach ($user->articles as $article) {
echo $article->title . '<br />';
}
//edit the user
$user->username = "johnny doe";
$userMapper->update($user);
//add a new user
$newUser = new User();
$newUser->username = "my username 2";
$userMapper->insert($newUser);
//delete a user
$userMapper->delete(4);
//get users with their articles
//get all users limited by 2, sorted by username ascending and eager load the article relationship
//only 2 queries - one for fetching the users and one for coupling the related articles
$users = $userMapper->findMany(array("limit" => 3, "sort" => array("username", "asc"), "relations" => array("Article")));
//4 queries: one for retrieving the users and 1 per user lazy loading the articles.
$users = $userMapper->findMany(array("limit" => 3, "sort" => array("username", "asc")));
echo sizeof($users) . " users found<br />";
foreach ($users as $user) {
echo "<br />Username:" . $user->username . "<br />";
if (sizeof($user->articles) > 0) {
echo "Articles of this user:<br />";
foreach ($user->articles as $article) {
echo $article->title . "<br />";
示例4: createAction
public function createAction()
{
$this->isAdmin();
if (isset($_POST['operator'])) {
$O_operator = new Operator();
$O_operator->setName($_POST['name']);
$O_operator->setFirstName($_POST['firstName']);
$O_operator->setSizeHarness($_POST['sizeHarness']);
$O_operator->setEmail($_POST['email']);
$O_operator->initInceptionDate();
$O_teamMapper = new TeamMapper();
$O_team = $O_teamMapper->findByTwoIds($_POST['staff_id'], $_POST['subgroup_id']);
$O_operator->setTeamId($O_team->getId());
$O_operatorMapper = new OperatorMapper();
$I_operatorId = $O_operatorMapper->insert($O_operator);
//die(header('Location:/user/default/'));
}
if (isset($_POST['inspector'])) {
$O_inspector = new Inspector();
$O_inspector->setName($_POST['name']);
$O_inspector->setFirstName($_POST['firstName']);
$O_inspector->setEmail($_POST['email']);
$O_inspector->setSubgroupId($_POST['subgroup_id']);
$O_inspector->initInceptionDate();
$O_inspectorMapper = new InspectorMapper();
$I_inspectorId = $O_inspectorMapper->insert($O_inspector);
}
$O_user = new User();
$O_user->setLogin($_POST['login']);
$O_user->setPassword($_POST['password']);
$O_user->setProfileId($_POST['profile_id']);
if (isset($_POST['operator'])) {
$O_user->setOperatorId($I_operatorId);
}
if (isset($_POST['inspector'])) {
$O_user->setInspectorId($I_inspectorId);
}
$O_userMapper = new UserMapper();
$I_userId = $O_userMapper->insert($O_user);
}