本文整理汇总了PHP中Model_User::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Model_User::add方法的具体用法?PHP Model_User::add怎么用?PHP Model_User::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model_User
的用法示例。
在下文中一共展示了Model_User::add方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_add
public function action_add()
{
$this->template->title = "Add Dosen";
if (isset($_POST['nip'])) {
$dosen = new Model_Dosen();
$user = new Model_User();
$user->username = $_POST['nip'];
$user->password = $_POST['password'];
$user->save();
// Masukkan role user
$user->add('roles', ORM::factory('role')->where('name', '=', 'login')->find());
$user->add('roles', ORM::factory('role')->where('name', '=', 'dosen')->find());
$dosen->nip = $_POST['nip'];
$dosen->user_id = $user->id;
$dosen->nama = $_POST['nama'];
$dosen->tahun_masuk = $_POST['tahun_masuk'];
$dosen->tempat_lahir = $_POST['tempat_lahir'];
$tanggal_lahir = $_POST['tahun'] . "-" . $_POST['bulan'] . "-" . $_POST['tanggal'];
$dosen->tanggal_lahir = $tanggal_lahir;
$dosen->jenis_kelamin = $_POST['jenis_kelamin'];
$dosen->alamat = $_POST['alamat'];
$dosen->no_hp = $_POST['no_hp'];
$dosen->telp_rumah = $_POST['telp_rumah'];
$dosen->email = $_POST['email'];
$dosen->save();
}
}
示例2: action_index
public function action_index()
{
$count = ORM::factory('User')->count_all();
if ($count === 0) {
$this->template->content = View::factory('install/index');
if ($this->request->method() === Request::POST) {
if (!Security::check($this->request->param('id'))) {
throw new Exception("Bad token!");
}
$post = Validation::factory($_POST)->rule('username', 'not_empty')->rule('email', 'not_empty')->rule('email', 'email')->rule('password', 'not_empty')->rule('password', 'min_length', array(':value', '8'))->rule('password2x', 'not_empty')->rule('password', 'matches', array(':validation', 'password', 'password2x'));
if ($post->check()) {
$user = new Model_User();
$post = $this->request->post();
$user->values($post)->save();
$adminRole = ORM::factory('Role')->where('name', '=', 'admin')->find();
$loginRole = ORM::factory('Role')->where('name', '=', 'login')->find();
$user->add('roles', $loginRole);
$user->add('roles', $adminRole);
$this->redirect('install/successful');
} else {
$this->redirect('install/oops');
}
}
} else {
$this->redirect('');
}
}
示例3: action_add
public function action_add()
{
$this->template->title = "Add Mahasiswa";
if (isset($_POST['nim'])) {
$mahasiswa = new Model_Mahasiswa();
$user = new Model_User();
$user->username = $_POST['nim'];
// nimnya harus dicek dulu nih
$user->password = $_POST['password'];
$user->save();
// Masukkan role user
$user->add('roles', ORM::factory('role')->where('name', '=', 'login')->find());
$user->add('roles', ORM::factory('role')->where('name', '=', 'mahasiswa')->find());
$mahasiswa->nim = $_POST['nim'];
// nimnya harus dicek dulu nih
$mahasiswa->user_id = $user->id;
$mahasiswa->nama = $_POST['nama'];
$mahasiswa->tempat_lahir = $_POST['tempat_lahir'];
$tanggal_lahir = $_POST['tahun'] . "-" . $_POST['bulan'] . "-" . $_POST['tanggal'];
$mahasiswa->tanggal_lahir = $tanggal_lahir;
$mahasiswa->jenis_kelamin = $_POST['jenis_kelamin'];
$mahasiswa->email = $_POST['email'];
$mahasiswa->alamat = $_POST['alamat'];
$mahasiswa->no_hp = $_POST['no_hp'];
$mahasiswa->nama_ayah = $_POST['nama_ayah'];
$mahasiswa->telp_rumah = $_POST['telp_rumah'];
$mahasiswa->tahun_masuk = $_POST['tahun_masuk'];
$mahasiswa->status_kelulusan = 2;
// belum lulus
$mahasiswa->save();
}
}
示例4: action_add
public function action_add()
{
$this->template->title = "Add User";
if (isset($_POST['username'])) {
$user = new Model_User();
$user->username = $_POST['username'];
$user->password = $_POST['password'];
$user->save();
// Masukkan role user
$user->add('roles', ORM::factory('role', $_POST['role']));
$role = new Model_Role($_POST['role']);
if ($role->name != 'login') {
$user->add('roles', ORM::factory('role')->where('name', '=', 'login')->find());
}
}
$select_role = array();
$roles = new Model_Role();
$roles = $roles->find_all();
foreach ($roles as $role) {
if ($role->name != 'dosen' && $role->name != 'mahasiswa') {
$select_role[$role->id] = $role->name;
}
}
$this->template->content->select_role = $select_role;
}
示例5: createUser
/**
* 创建用户
* @param array $userInfo 用户信息
* @return boolean
*/
public function createUser($userInfo)
{
$this->_modelUser = $this->_getGlobalData('Model_User', 'object');
$this->_modelUser->add($userInfo);
$userInfo['Id'] = $this->_modelUser->returnLastInsertId();
$userClass = new Object_UserInfo();
$userClass->registerUserInfo($userInfo);
$userClass->setUpdateInfo(1);
$userClass = null;
$this->_modelUser->createCache();
return true;
}
示例6: prepare
/**
* @BeforeSuite
*/
public static function prepare(SuiteEvent $event)
{
// Clear the user table.
$query = DB::delete('users')->execute();
// Setup the test user for login.
$user = new Model_User();
$user->username = 'username';
$user->password = 'password';
$user->email = 'username@test.com';
$user->timezone_id = 1;
$user->create();
$user->add('roles', Model_Role::LOGIN);
}
示例7: action_index
public function action_index()
{
$view = View::factory('register');
if ($this->request->method() === Request::POST) {
if (!Security::check($this->request->param('id'))) {
throw new Exception("Bad token!");
}
$post = Validation::factory($_POST)->rule('username', 'not_empty')->rule('username', 'Model_User::is_username_taked')->rule('email', 'not_empty')->rule('email', 'Model_User::unique_email')->rule('email', 'email')->rule('password', 'not_empty')->rule('password', 'min_length', array(':value', '8'))->rule('password_again', 'not_empty')->rule('password', 'matches', array(':validation', 'password', 'password_again'));
if ($post->check()) {
$user = new Model_User();
$post = $this->request->post();
$user->values($post)->save();
// atrod role 'login'
$loginRole = ORM::factory('Role')->where('name', '=', 'login')->find();
// pieliek klāt 'login' role litotājam
$user->add('roles', $loginRole);
$this->template->content = $view->bind('successful', $this->true);
} else {
$this->template->content = $view->bind('errors', $this->true);
}
}
$this->template->content = $view->render();
}
示例8: action_adduser
public function action_adduser()
{
if (!empty($_SESSION['kids_id'])) {
if (empty($_SESSION['kidsData'])) {
$_SESSION['kidData'] = Helper_Mmdb::getUserData($_SESSION['kids_id']);
}
$user = new Model_User();
$userData = array();
$userData['username'] = Model_User::create_unique_display_name();
$userData['password'] = !empty($_SESSION['loginInfo']['password']) ? $_SESSION['loginInfo']['password'] : Model_User::create_unique_display_name();
$userData['password_confirm'] = $userData['password'];
$userData['birthdate'] = $_POST['birthdate'];
$userData['gender'] = $_POST['gender'];
$userData['display_name'] = $_POST['display_name'];
$userData['email'] = $_POST['email'];
if (empty($_POST['vanity_url'])) {
$userData['vanity_url'] = strtolower(preg_replace("/[^A-Za-z0-9 ]/", "-", $userData['display_name']));
} else {
$userData['vanity_url'] = $_POST['vanity_url'];
}
//check vanity for uniqueness
$checkVanity = ORM::factory("user")->where("vanity_url", "=", $userData['vanity_url'])->find();
$vanId = 1;
while ($checkVanity->loaded()) {
$checkVanity = ORM::factory("user")->where("vanity_url", "=", $userData['vanity_url'] . "-{$vanId}")->find();
if (!$checkVanity->loaded()) {
$userData['vanity_url'] .= "-{$vanId}";
break;
}
$vanId++;
}
/* Load the validation rules, filters etc.*/
$post = $user->validate_create($userData);
/* If the post data validates using the rules setup in the user model. */
if ($post->check()) {
/* Affects the sanitized vars to the user object. */
$user->values($post);
/* Create the account. */
$user->kids_id = $_SESSION['kids_id'];
$user->save();
/* Add the login role to the user. */
$login_role = new Model_Role(array('name' => 'login'));
$user->add('roles', $login_role);
/* Add approval. */
$this->setup_approval($user);
/* Sign the user in. */
Auth::instance()->login($post['username'], $post['password']);
/* Redirect to the user account. */
Request::instance()->redirect('profile');
} else {
/* Get errors for display in view. */
Message::set(Message::ERROR, $post->errors('user'));
$this->action_merge();
}
} else {
Request::instance()->redirect('account/signin');
}
}
示例9: add_edit
protected function add_edit(Model_User &$user)
{
$errors = array();
$roles = ORM::factory('Role')->where('id', '!=', Model_User::LOGIN_ROLE_ID)->order_by('id')->find_all()->as_array('id');
if ($this->request->method() == Request::POST) {
$data = $this->request->post();
$_data = $data;
// operate on copy: $_data
$email = $user->email;
// keep email in the case od validation exception to restore this value in $user
$external_validation = Validation::factory($_data)->labels(array('repeat_email' => 'Repeat e-mail'))->rules('roles', array(array('each_in_array', array(':value', array_keys($roles)))))->rules('repeat_email', array(array('matches', array(':validation', ':field', 'email'))));
if ($user->loaded()) {
if (empty($_data['email'])) {
// no email while editing means: no changing but ORM model need email value to be not empty
$_data['email'] = $user->email;
}
} else {
$_data['password'] = Text::random('alnum', 14);
// set random password for new user
}
try {
$user->values($_data)->save($external_validation);
} catch (ORM_Validation_Exception $vex) {
$errors = $vex->errors('orm');
$user->email = $email;
// restore original email value
}
// Manage roles for user:
if (empty($errors)) {
$user_roles = (array) Arr::get($data, 'roles', array());
foreach ($roles as $role) {
// Adding:
if (in_array($role->id, $user_roles) and !$user->has_role($role->id)) {
$user->add('roles', $role);
}
// Removing:
if (!in_array($role->id, $user_roles) and $user->has_role($role->id)) {
$user->remove('roles', $role);
}
}
if (!empty($data['send_hashlink'])) {
$this->send_activation($user);
}
// finish saving
return TRUE;
}
} else {
if ($user->loaded()) {
$data = $user->as_array();
$data['email'] = '';
$data['roles'] = array();
foreach ($roles as $role) {
if ($user->has_role($role->id)) {
$data['roles'][] = $role->id;
}
}
} else {
$data = array('send_hashlink' => '1');
}
}
$this->content = View::factory("users/edit")->bind("user", $user)->bind("roles", $roles)->bind("data", $data)->bind("errors", $errors);
}