本文整理汇总了PHP中ORM::update方法的典型用法代码示例。如果您正苦于以下问题:PHP ORM::update方法的具体用法?PHP ORM::update怎么用?PHP ORM::update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ORM
的用法示例。
在下文中一共展示了ORM::update方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Overload `ORM::update` to support versioned data
*
* @param Validation $validation Validation object
* @return ORM
*/
public function update(Validation $validation = NULL)
{
if (!$this->_restore) {
$this->_last_version = 1 + ($this->_last_version === NULL ? $this->_object['version'] : $this->_last_version);
$this->__set('version', $this->_last_version);
$object = DB::select()->from($this->_table_name)->where($this->_primary_key, '=', $this->pk())->execute($this->_db)->current();
}
parent::update($validation);
// Create version only if its general update not version restore
if ($this->_saved and !$this->_restore) {
$data = array();
foreach ($object as $key => $value) {
if ($key === $this->_primary_key or array_key_exists($key, $this->_ignored_columns)) {
continue;
}
if ($key === 'version') {
// Always use the current version
$value = $this->_last_version;
}
//make sure only column names except primary key is stored in revision
if (array_key_exists($key, $this->_table_columns)) {
$data[$key] = $value;
}
}
$data[$this->foreign_key()] = $this->id;
DB::insert($this->version_table())->columns(array_keys($data))->values(array_values($data))->execute($this->_db);
}
return $this;
}
示例2: array
return false;
}
$launchkeys = array("course_id" => $crs->id(), "user_id" => $usr->id());
if ($org && $org->id()) {
$launchkeys[org_id] = $org->id();
} else {
// Make sure to never get a org with a primary key of -1
$launchkeys[org_id] = -1;
}
$launch->read($launchkeys);
$launch->setall($launchkeys);
// Set the foreign keys
$launch->setall($_REQUEST, '/^launch_/');
$launchpassword = md5(uniqid(rand(), true));
if ($launch->id()) {
$launch->update();
DPRT("Updated launch={$launch->id}()");
} else {
$launch->insert();
DPRT("Added launch={$launch->id}()");
}
// Log this digest
$reqstr = mysql_real_escape_string(print_r($_REQUEST, TRUE));
$quer = "insert into lti_digest (created_at, digest, request) values (NOW(), '{$digest}', '{$reqstr}');";
mysql_query($quer);
// Time to return a response, we either return a web service
// response, debug outtput, or redirect back to ourselves
$theurl = $_SERVER[SCRIPT_URI];
$theuri = $_SERVER[REQUEST_URI];
$i = strpos($theuri, '?');
if ($i > 0) {
示例3: array
echo "<h4 class='alert-danger'> User Ext. is required</h4>";
$key = 1;
}
if ($key == 0) {
// image handling
if (!empty($_FILES['image']['name'])) {
$image_path = "images/users/" . $_FILES['image']['name'];
move_uploaded_file($_FILES["image"]["tmp_name"], $image_path);
$image = $_FILES['image']['name'];
} else {
$image = 'default.png';
}
// database update
$user = array('name' => $_POST["name"], 'email' => $_POST["email"], 'password' => hash("md5", $_POST['password']), 'room_no' => $_POST["room"], 'ext' => $_POST["ext"], 'is_admin' => 0, 'pic' => $image);
$where = array('id' => $_POST["id"]);
$result = $mydb->update($where, $user);
header("Location: Users.php");
}
}
?>
<h1>Edit User</h1>
<form method="post" action="EditUser.php" class="form-horizontal" enctype="multipart/form-data">
<div class="form-group panel">
<label class="control-label">Name</label>
<input required type="name" name="name" class="form-control" value="<?php
echo $row['name'];
?>
" >
<label class="control-label">Email</label>
<input required type="email" name="email" class="form-control" value="<?php
示例4: sso_signup
/**
* Sign-up using data from OAuth provider.
*
* Override this method to add your own sign up process.
*
* @param ORM $user
* @param array $data
* @param string $provider
* @return ORM
*/
public function sso_signup(ORM $user, array $data, $provider_field)
{
if (!$user->loaded()) {
// Add user
$user->{$provider_field} = $data['id'];
$user->user_type = 0;
$user->username = $provider_field . $data['id'];
$user->user_password = md5($user->username . microtime(TRUE));
if ($provider_field == 'vkontakte_id' or $provider_field == 'facebook_id') {
$user->email = $user->username . '@bt-lady.com.ua';
$user->firstname = $data['first_name'];
$user->lastname = $data['last_name'];
if (array_key_exists('birthday', $data) or array_key_exists('bdate', $data)) {
$date_key = isset($data['bdate']) ? 'bdate' : 'birthday';
$date = NULL;
try {
$_date = new DateTime($data[$date_key]);
$date = $_date->format('d-m-Y');
} catch (Exception $e) {
}
$user->birthday = $date;
}
if (array_key_exists('email', $data)) {
$user->email = $data['email'];
}
if (array_key_exists('photo_big', $data)) {
$user->avatar = $data['photo_big'];
}
if (array_key_exists('location', $data) or array_key_exists('hometown', $data)) {
$key = isset($data['location']) ? 'location' : 'hometown';
if (is_array($data[$key]) and array_key_exists('name', $data[$key])) {
$user->user_from = $data[$key]['name'];
}
}
if (array_key_exists('city', $data) and array_key_exists('country', $data)) {
$user->city_id = ORM::factory('city', array('vkontakte_cid' => $data['city']));
}
} elseif ($provider_field == 'twitter_id') {
$user->email = $data['screen_name'] . '@twitter.com';
}
// Save user
$user->save();
$user->add('roles', ORM::factory('role', array('name' => $provider_field)));
$user->add('roles', ORM::factory('role', array('name' => 'social')));
$user->update();
} elseif ($user->loaded() and empty($user->{$provider_field})) {
// If user is found, but provider id is missing add it to details.
// We can do this merge, because this means user is found by email address,
// that is already confirmed by this OAuth provider, so it's considered trusted.
$user->{$provider_field} = $data['id'];
// Save user
$user->save();
}
// Return user
return $user;
}
示例5: update
public function update(Validation $validation = NULL)
{
if (!$validation) {
$validation = Validation::factory(array('content' => $this->content, 'user_id' => $this->user_id));
}
$validation->rule('user_id', 'not_empty')->rule('content', 'not_empty')->rule('content', array($this, 'verify_word_count'), array('content', ':value'))->rule('content', 'max_length', array(':value', 100000));
$this->points = $this->calculate_points();
if ($this->changed('content')) {
$this->rid = '';
// resetting the RID as it needs to be recalculated when the page is updated
}
return parent::update($validation);
}
示例6: update
/**
* Updates a single record or multiple records
*
* @chainable
* @param Validation $validation Validation object
* @return ORM
*/
public function update(Validation $validation = NULL)
{
parent::update($validation);
$this->reload_config();
}
示例7: update
/**
* Override the create method with defaults
*
* @throws Gleez_Exception
*/
public function update(Validation $validation = NULL)
{
if (!$this->_loaded) {
throw new Gleez_Exception('Cannot Update :model model because it is not loaded.', array(':model' => $this->_object_name));
}
$this->data = $this->_data();
return parent::update($validation);
}
示例8: array
}
if ($key == 0) {
// image handling
if (!empty($_FILES['image']['name'])) {
$image_path = "images/products/" . $_FILES['image']['name'];
move_uploaded_file($_FILES["image"]["tmp_name"], $image_path);
$image = $_FILES['image']['name'];
} else {
$image = 'default.jpg';
}
// database insertion
$selected = $cat_db->select(array('name' => $_POST["category"]));
$category = $selected->fetch_assoc();
$product = array('name' => $_POST["product_name"], 'price' => $_POST["price"], 'category_id' => $category['id'], 'is_available' => 1, 'pic' => $image);
$where = array('id' => $_POST["id"]);
$result = $prod_db->update($where, $product);
header("Location: Products.php");
}
}
?>
<h1>Edit Product</h1>
<form method="post" action="EditProduct.php" class="form-horizontal" enctype="multipart/form-data">
<div class="form-group panel">
<label class="control-label">Product Name</label>
<input type="text" name="product_name" class="form-control" value="<?php
echo $row['name'];
?>
"><br>
<label>Price</label><br>
<input type="number" name="price" min="0" class="form-control price" value="<?php
示例9: save
/**
* Saves the current object. Will hash password if it was changed.
*
* @return ORM
*/
public function save()
{
if (array_key_exists('password', $this->_changed)) {
$this->_object['password'] = Auth::instance()->hash_password($this->_object['password']);
}
if (isset($this->_object['id'])) {
return parent::update();
} else {
return parent::create();
}
}
示例10: ORM
<?php
session_start();
if ($_POST) {
require_once 'database/model.php';
$mydb = new ORM();
$mydb->setTable("users");
$users = $mydb->select_all();
$found = 0;
while ($row = $users->fetch_assoc()) {
if ($_POST['email'] == $row["email"]) {
// send mail
$message = "your new password is: iti";
mail($_POST['email'], "New Password", $message);
$where = array('id' => $row['id']);
$new_pass = array('password' => hash("md5", "iti"));
$result = $mydb->update($where, $new_pass);
echo "<h4 class='alert-success'>Mail with the new password is sent to " . $row["email"] . "</h4>";
$found = 1;
}
}
if (!$found) {
echo "<h4 class='alert-danger'> email is incorrect</h4>";
}
}
?>
<h1 class="title">My Cafe</h1><br>
<div class="form-group">
<label class="control-label">Email</label>
<input type="email" name="email" class="form-control " required><br>
<button type="submit" value="mail" class="btn btn-info">Send new password</button>
</div>