本文整理汇总了PHP中MY_Model::update_by方法的典型用法代码示例。如果您正苦于以下问题:PHP MY_Model::update_by方法的具体用法?PHP MY_Model::update_by怎么用?PHP MY_Model::update_by使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MY_Model
的用法示例。
在下文中一共展示了MY_Model::update_by方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update_image
/**
* Update an existing image
*
* @author Yorick Peterse - PyroCMS Dev Team
* @modified by Jerel Unruh - PyroCMS Dev Team to add crop
* @access public
* @param int $id The ID of the image
* @param array $input The data used for updating the image
* @return mixed
*/
public function update_image($id, $input)
{
// Get the data related to the image we're working with
$image = $this->db->from('gallery_images')->join('galleries', 'gallery_images.gallery_id = galleries.id')->where('gallery_images.id', $id)->get()->row();
// Set the paths
$full_path = 'uploads/galleries/' . $image->slug . '/full/' . $image->filename . $image->extension;
$thumb_path = 'uploads/galleries/' . $image->slug . '/thumbs/' . $image->filename . '_thumb' . $image->extension;
// Crop an existing thumbnail
if ($input['thumb_width'] && $input['thumb_height'] > '1') {
// Get the required values for cropping the thumbnail
$size_array = getimagesize($full_path);
$width = $size_array[0];
$height = $size_array[1];
$scaled_height = $input['scaled_height'];
$scaled_percent = $scaled_height / $height;
$options['width'] = $input['thumb_width'] / $scaled_percent;
$options['height'] = $input['thumb_height'] / $scaled_percent;
$options['x_axis'] = $input['thumb_x'] / $scaled_percent;
$options['y_axis'] = $input['thumb_y'] / $scaled_percent;
$options['create_thumb'] = FALSE;
$options['maintain_ratio'] = $input['ratio'];
// Crop the fullsize image first
if ($this->resize('crop', $full_path, $full_path, $options) !== TRUE) {
return FALSE;
}
//Create a new thumbnail from the newly cropped image
// Is the current size larger? If so, resize to a width/height of X pixels (determined by the config file)
if ($options['width'] > $this->config->item('image_thumb_width')) {
$options['width'] = $this->config->item('image_thumb_width');
}
if ($options['height'] > $this->config->item('image_thumb_height')) {
$options['height'] = $this->config->item('image_thumb_height');
}
// Set the thumbnail option
$options['create_thumb'] = TRUE;
$options['maintain_ratio'] = TRUE;
//create the thumbnail
if ($this->resize('resize', $full_path, 'uploads/galleries/' . $image->slug . '/thumbs/', $options) !== TRUE) {
return FALSE;
}
} else {
if (isset($input['delete'])) {
// First we'll delete it from the DB
if (parent::delete($id)) {
// Change the table
$this->table = 'galleries';
// Unset the thumbnail for each gallery that was using this image
if (parent::update_by('thumbnail_id', $id, array('thumbnail_id' => NULL))) {
// Change the table back
$this->table = 'gallery_images';
// Delete the files
if (unlink($full_path) === TRUE and unlink($thumb_path) === TRUE) {
return TRUE;
} else {
return FALSE;
}
} else {
return FALSE;
}
} else {
return FALSE;
}
}
}
// Just save it already, do note that data isn't saved if the user decides to delete an image
$to_update['title'] = $input['title'];
$to_update['description'] = $input['description'];
$to_update['updated_on'] = time();
return parent::update($id, $to_update);
}
示例2: update_entry
public function update_entry($id, $post, $stream_entry_id)
{
$data = array('date_start' => $post['date_start']['date'] . ' ' . $post['date_start']['hour'] . ':' . $post['date_start']['minute'] . ':00', 'date_end' => $post['date_end']['date'] . ' ' . $post['date_end']['hour'] . ':' . $post['date_end']['minute'] . ':00', 'restricted_to' => isset($post['restricted_to']) ? in_array('0', $post['restricted_to']) ? '0' : implode(',', $post['restricted_to']) : null, 'category' => $post['category'], 'recurrence' => $post['recurrence'], 'updated_on' => now());
return parent::update_by('id', $id, $data);
}