本文整理汇总了PHP中Jelly::delete方法的典型用法代码示例。如果您正苦于以下问题:PHP Jelly::delete方法的具体用法?PHP Jelly::delete怎么用?PHP Jelly::delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jelly
的用法示例。
在下文中一共展示了Jelly::delete方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: submit
protected function submit($task, $id, $type)
{
$item = Jelly::select($type, $id);
$redirect = HTML::uri(array('action' => Inflector::plural($type)));
switch ($task) {
case 'apply':
$item->set($_POST)->save();
$redirect = HTML::uri(array('action' => $type, 'task' => 'edit', 'id' => $item->id));
$this->request->redirect($redirect);
break;
case 'save':
$item->set($_POST)->save();
$this->request->redirect($redirect);
break;
case 'cancel':
$this->request->redirect($redirect);
break;
case 'delete':
if ($ids = Arr::get($_POST, 'cid', NULL)) {
$items = Jelly::delete($item)->where(':primary_key', 'IN', $ids)->execute();
}
$this->request->redirect($redirect);
break;
case 'default':
if (!$item->loaded()) {
$this->request->redirect($redirect);
}
break;
}
return $item;
}
示例2: initialize
/**
* Create new model
*
* @param Jelly_Meta $meta
*/
public static function initialize(Jelly_Meta $meta)
{
$meta->fields(array('id' => new Field_Primary(), 'token' => new Field_String(array('unique' => true, 'rules' => array('max_length' => array(32)))), 'user' => new Field_BelongsTo(), 'user_agent' => new Field_String(), 'created' => new Field_Timestamp(array('auto_now_create' => true)), 'expires' => new Field_Timestamp()));
// Garbace collection
if (mt_rand(1, 100) === 1) {
Jelly::delete('user_token')->where('expires', '<', time())->execute();
}
}
示例3: save
/**
* Implementation for Jelly_Field_Behavior_Saveable.
*
* @param Jelly $model
* @param mixed $value
* @return void
*/
public function save($model, $value, $loaded)
{
// Find all current records so that we can calculate what's changed
$in = $loaded ? $this->_in($model, true) : array();
// Find old relationships that must be deleted
if ($old = array_diff($in, (array) $value)) {
Jelly::delete($this->through['model'])->where($this->through['columns'][0], '=', $model->id())->where($this->through['columns'][1], 'IN', $old)->execute(Jelly::meta($model)->db());
}
// Find new relationships that must be inserted
if (!empty($value) && ($new = array_diff((array) $value, $in))) {
foreach ($new as $new_id) {
if (!is_null($new_id)) {
Jelly::insert($this->through['model'])->columns($this->through['columns'])->values(array($model->id(), $new_id))->execute(Jelly::meta($model)->db());
}
}
}
}
示例4: save
/**
* Implementation for Jelly_Field_Behavior_Saveable.
*
* @param Jelly $model
* @param mixed $value
* @return void
*/
public function save($model, $value, $loaded)
{
// Find all current records so that we can calculate what's changed
$in = $loaded ? $this->_in($model, TRUE) : array();
// Find old relationships that must be deleted
if ($old = array_diff($in, (array) $value)) {
Jelly::delete($this->through['model'])->where($this->through['columns'][0], '=', $model->id())->where($this->through['columns'][1], 'IN', $old)->execute(Jelly::meta($model)->db());
}
// Find new relationships that must be inserted
if ($new = array_diff((array) $value, $in)) {
foreach ($new as $new_id) {
// Not sure why an array with NULL as the first value was coming through when you didn't submit anything
// on the manytomany relationship but this avoids the problem for now...
if ($new_id == NULL) {
continue;
}
/*
if (class_exists(Jelly::class_name($this->through['model']))) {
Jelly::factory(
$this->through['model'],
array(
$this->through['columns'][0] => $model->id(),
$this->through['columns'][1] => $new_id
)
)->save();
} else {
*/
Jelly::insert($this->through['model'])->columns($this->through['columns'])->values(array($model->id(), $new_id))->execute(Jelly::meta($model)->db());
//}
}
}
}
示例5: delete
/**
* Deletes a single record.
*
* @param $key A key to use for non-loaded records
* @return boolean
**/
public function delete($key = NULL)
{
$result = FALSE;
// Are we loaded? Then we're just deleting this record
if ($this->_loaded or $key) {
if ($this->_loaded) {
$key = $this->id();
}
$result = Jelly::delete($this)->where(':unique_key', '=', $key)->execute();
}
// Clear the object so it appears deleted anyway
$this->clear();
return (bool) $result;
}
示例6: delete
/**
* Deletes a single record.
*
* @param $key A key to use for non-loaded records
* @return boolean
**/
public function delete($key = NULL)
{
$result = FALSE;
// Are we loaded? Then we're just deleting this record
if ($this->_loaded or $key) {
if ($this->_loaded) {
$key = $this->id();
}
// Call delete on each individual field so they can clean up after themselves
foreach ($this->_meta->fields() as $field) {
$field->delete($this);
}
$result = Jelly::delete($this)->where(':unique_key', '=', $key)->execute();
}
// Clear the object so it appears deleted anyway
$this->clear();
return (bool) $result;
}
示例7: logout
/**
* Log a user out and remove any auto-login Cookies.
*
* @param boolean completely destroy the session
* @param boolean remove all tokens for user
* @return boolean
*/
public function logout($destroy = FALSE, $logout_all = FALSE)
{
if ($token = Cookie::get('authautologin')) {
// Delete the autologin Cookie to prevent re-login
Cookie::delete('authautologin');
// Clear the autologin token from the database
$token = Jelly::select('user_token')->where('token', '=', $token)->limit(1)->load();
if ($token->loaded() and $logout_all) {
Jelly::delete('user_token')->where('user_id', '=', $token->user->id)->execute();
} elseif ($token->loaded()) {
$token->delete();
}
}
return parent::logout($destroy);
}
示例8: logout
/**
* Log out a user by removing the related session variables.
*
* @param boolean $destroy Completely destroy the session
* @param boolean $logout_all Logout all browsers
* @return boolean
*/
public function logout($destroy = false, $logout_all = false)
{
// Delete the autologin cookie to prevent re-login
if ($token = Cookie::get($this->_config['cookie_name'])) {
Cookie::delete($this->_config['cookie_name']);
$token = Jelly::select('user_token')->where('token', '=', $token)->limit(1)->load();
if ($token->loaded() && $logout_all) {
Jelly::delete('user_token')->where('user_id', '=', $token->user->id)->execute();
} else {
if ($token->loaded()) {
$token->delete();
}
}
}
// Logout 3rd party?
/*
if (FB::enabled() && Visitor::instance()->get_provider()) {
$this->session->delete($this->config['session_key'] . '_provider');
try {
FB::instance()->expire_session();
} catch (Exception $e) { }
}
*/
// Destroy the session completely?
if ($destroy === true) {
$this->_session->destroy();
} else {
// Remove the user from the session
$this->_session->delete($this->_config['session_key']);
// Regenerate session_id
$this->_session->regenerate();
}
// Double check
return !$this->logged_in();
}