本文整理匯總了PHP中models\User::fromArray方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::fromArray方法的具體用法?PHP User::fromArray怎麽用?PHP User::fromArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models\User
的用法示例。
在下文中一共展示了User::fromArray方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: create
protected function create()
{
$params = arrayKeysSnakeToCamel($_POST['user']);
$user = new User();
$user->fromArray($params);
$user->save();
$this->addFlash("success", "registered");
redirectTo("/");
}
示例2: create
protected function create()
{
if (isset($_POST["email"]) && isset($_POST["username"]) && isset($_POST["password"])) {
$user = new User();
$emailConfirmToken = uniqid() . generateRandomString(19);
$user->fromArray(array("Email" => $_POST["email"], "Username" => $_POST["username"], "Password" => $_POST["password"], "EmailConfirmToken" => $emailConfirmToken));
if (!$user->save()) {
$failures = $user->getValidationFailures();
if (count($failures) > 0) {
foreach ($failures as $failure) {
$this->sendFlashMessage("You have not been signed up. " . $failure->getMessage(), "error");
}
}
} else {
$this->sendFlashMessage('You have been successfuly signed up. Please confirm your email address, we have send confirmation link. <a class="link" href="/user/' . $user->getUsername() . '/send-email-confirm-email">Send new email confirm link?</a>', "success");
$body = '<p>You have created new account on Starling.</p><br /><p>Please virify your email address by clicking this url:</p><a href="' . $this->siteURL . '/user/' . $user->getUsername() . '/email-confirm/' . urlencode($emailConfirmToken) . '">' . $this->siteURL . '/user/' . $user->getUsername() . '/email-confirm/' . urlencode($emailConfirmToken) . '</a>';
$transport = \Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')->setUsername($this->emailAddress)->setPassword($this->emailPassword);
$mailer = \Swift_Mailer::newInstance($transport);
$message = \Swift_Message::newInstance()->setSubject('Email verification')->setFrom(array($this->emailAddress => 'Starling admin'))->setTo(array($user->getEmail() => $user->getUsername()))->setBody($body, 'text/html');
$result = $mailer->send($message);
}
$this->redirect("/");
} else {
setHTTPStatusCode("400");
}
}