本文整理匯總了PHP中models\User::create方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::create方法的具體用法?PHP User::create怎麽用?PHP User::create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models\User
的用法示例。
在下文中一共展示了User::create方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: ajaxSignUp
public function ajaxSignUp()
{
extract($_POST['input']);
$user = \Models\User::checkUsernameForRegistration($username);
if (isset($user['id'])) {
$data['name'] = 'username';
$data['notice'] = 'This username is not available. Please try another.';
echo json_encode($data, JSON_UNESCAPED_UNICODE);
die;
}
$user = \Models\User::checkEmailForRegistration($email);
if (isset($user['id'])) {
$data['name'] = 'email';
$data['notice'] = 'This email is already used when registering. Please try another.';
echo json_encode($data, JSON_UNESCAPED_UNICODE);
die;
}
if (!isset($user['id'])) {
$user = \Models\User::create($email, $username, sha1($password), $f_name, $l_name, $member, sha1($username));
if (isset($user['username'])) {
$data['notice'] = true;
echo json_encode($data, JSON_UNESCAPED_UNICODE);
}
}
}
示例2: postCreate
public function postCreate(Request $request)
{
$users = User::create();
$users->set($request->request->all());
$users->save();
return $this->show($users->id);
}
示例3: create
public function create()
{
$args = $this->request->args;
$username = Validate::plaintext($args['username']);
$password = Validate::password($args['password']);
$address = Validate::plaintext($args['address']);
$user = User::create($username, $password, $address);
$this->response->set_header(Lib\Response::HTTP_CREATED);
$this->response->set('user', $user);
}
示例4: setUp
/**
* Setup the test environment.
*/
public function setUp()
{
parent::setUp();
// Create an artisan object for calling migrations
$artisan = $this->app->make('Illuminate\\Contracts\\Console\\Kernel');
// Call migrations specific to our tests, e.g. to seed the db
$artisan->call('migrate', array('--database' => 'testbench', '--path' => '../tests/database/migrations'));
$fakeNow = Carbon::createFromFormat('Y-m-d H:i:s', '2015-01-01 00:00:01');
Carbon::setTestNow($fakeNow);
$user = User::create(['name' => 'Dolly', 'email' => 'dolly@example.com']);
$author = Author::create(['user_id' => $user->id, 'role' => 'editor']);
}
示例5: it_deletes_all_specified_relations
/** @test */
public function it_deletes_all_specified_relations()
{
$user = User::create([]);
$author = Author::create(['user_id' => $user->id]);
$post = Post::create(['author_id' => $author->id]);
$comment = Comment::create(['post_id' => $post->id]);
$user = $user->fresh();
$this->assertEquals($user->author()->count(), 1, 'author');
$this->assertEquals($user->author()->first()->posts()->count(), 1, 'posts');
$this->assertEquals($user->author()->first()->posts()->first()->comments()->count(), 1, 'comments');
$user->delete();
$this->assertEquals(Post::where('author_id', 1)->count(), 0, 'post 0');
$this->assertEquals(Comment::where('post_id', 1)->count(), 0, 'comment 0');
$this->assertEquals(Author::where('user_id', 1)->count(), 0, 'user 0');
}
示例6: addAction
public function addAction()
{
$formData = [];
if ($this->request->isPost()) {
if ($this->security->checkToken()) {
$formData = $this->request->getPost();
$userModel = new User();
$userModel->name = $formData['name'];
$userModel->email = $formData['email'];
$userModel->password = $this->security->hash($formData['password']);
$userModel->gender = $formData['gender'];
$userModel->role = $formData['role'];
$userModel->status = $formData['status'];
if ($userModel->create()) {
$formData = [];
$this->flash->success('Add user successfully');
} else {
$this->flash->outputMessage('error', $userModel->getMessages());
}
}
}
$this->view->setVars(['formData' => $formData, 'roles' => User::$roles, 'status' => User::$statusName]);
$this->tag->prependTitle('Add user');
}
示例7: add
public function add()
{
$user_model = new User();
$album_model = new Album();
$role_model = new Role();
$status_model = new Status();
$this->data['title'] = 'Add Artist';
if (isset($_POST) && !empty($_POST)) {
$artistArray = array('user_firstname' => $_POST['firstname'], 'user_stagename' => $_POST['stagename'], 'user_bio' => $_POST['bio'], 'twitter_handle' => $_POST['twitter_handle'], 'user_status_id' => Status::id('active'), 'user_role_id' => Role::id('artist'), 'user_created' => time());
$artistArray = Gump::xss_clean($artistArray);
$artistArray = Gump::sanitize($artistArray);
$artist_id = $user_model->create($artistArray);
if ($artist_id > 0) {
$this->data['success'] = 'Artist Added!';
$slug = Url::generateSafeSlug($_POST['stagename'] . $artist_id);
$user_model->updateId(array('user_slug' => $slug), $artist_id);
} else {
$this->data['error'] = 'Operation Fails!';
}
//UPLOAD ATTACHMENT
if ($_FILES["image"]["tmp_name"] != '') {
//upload image into uploads folder
Upload::setName($slug . uniqid());
Upload::resizeUpload($_FILES["image"], UPLOAD_PATH, '450px');
$update_data = array('user_image' => Upload::getFileName('images'));
$this->user_model->updateId($update_data, $artist_id);
}
//GET INSERTED ID
$this->data['user_data'] = $user_model->find($insert_id);
Url::redirect('artist');
}
View::rendertemplate('header', $this->data);
View::rendertemplate('sidebar', $this->data);
View::render('artist/artist.add', $this->data);
View::rendertemplate('footer', $this->data);
}
示例8: signup
public function signup($slug = null)
{
$this->data['title'] = 'Join Us';
$statusModel = new Status();
$roleModel = new Role();
$userModel = new User();
if (isset($_POST['email']) && !empty($_POST['email'])) {
$firstname = $_POST['firstname'];
$email = $_POST['email'];
if ($_POST['password'] == $_POST['password2']) {
$encrypted = md5($_POST['password']);
$row_count = $userModel->getColRow('user_email', $email);
if (!is_bool($row_count)) {
Session::set('error', 'Email exists in our records, please use a different email');
} else {
$userArray = array('user_firstname' => $firstname, 'user_email' => $email, 'user_password' => $encrypted, 'user_role_id' => Role::id('user'), 'user_status_id' => Status::id('active'));
$userArray = Gump::xss_clean($userArray);
$userArray = Gump::sanitize($userArray);
$is_valid = Gump::is_valid($userArray, array('user_firstname' => 'required|max_len,200|min_len,1', 'user_email' => 'required|max_len,200|min_len,1', 'user_password' => 'required|max_len,200|min_len,1'));
if ($is_valid === true) {
$user_id = $userModel->create($userArray);
if ($user_id > 0) {
$slug = Url::generateSafeSlug($firstname . $user_id);
//send email
$subject = 'Welcome to GbeduMobile';
$content .= "You just opened a new account with us, Get login details below<br><br>";
$content .= "Username: " . $email . "<br>";
$content .= "Password: " . $_POST['password'] . "<br>";
if (ENVIRONMENT == 'production') {
$mail = new Mail();
$mail->general($email, $subject, $firstname, $content);
}
Session::set('success', 'Login details has been sent to your email, Congrats!');
Url::redirect('home');
} else {
Session::set('error', 'Operation Fails, Please contact admin');
}
} else {
Session::set('error', $is_valid);
}
}
} else {
Session::set('error', 'Password does not match!');
}
}
View::rendertemplate('header', $this->data);
View::render('account/signup', $this->data);
View::rendertemplate('footer', $this->data);
}