1
0
Fork 0

Add simple gallery.

This commit is contained in:
Andrew Tomaka 2011-11-06 02:34:41 -05:00
parent d8d4279c69
commit 4ce532cf65
5 changed files with 66 additions and 2 deletions

View file

@ -0,0 +1,31 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Gallery extends CI_Controller {
public function index() {
$this->load->model('fileupload');
$this->load->library('pagination');
$page_count = 20;
$start = $this->uri->segment($this->uri->total_segments(), 1);
if($start == 'index') $start = 1;
$config = array(
'base_url' => base_url('/gallery/index/'),
'total_rows' => $this->fileupload->count_uploads(),
'per_page' => $page_count
);
$this->pagination->initialize($config);
$this->data['pagination'] = $this->pagination->create_links();
$this->data['uploads'] = $this->fileupload->get_uploads($start, $page_count);
$this->template->load('template', 'gallery', $this->data);
}
}
?>

View file

@ -34,7 +34,7 @@ class Upload extends CI_Controller {
'create_thumb' => true, 'create_thumb' => true,
'maintain_ratio' => true, 'maintain_ratio' => true,
'width' => 175, 'width' => 175,
'height' => 50, 'height' => 175,
'new_image' => './thumbs/' . $file_name . $upload['file_ext'], 'new_image' => './thumbs/' . $file_name . $upload['file_ext'],
'thumb_marker' => '', 'thumb_marker' => '',
); );

View file

@ -32,6 +32,12 @@ class Fileupload extends CI_Model {
function add_view($id) { function add_view($id) {
$this->db->query("UPDATE uploads SET views = views + 1 WHERE id = $id"); $this->db->query("UPDATE uploads SET views = views + 1 WHERE id = $id");
} }
function get_uploads($start = false, $count = false) {
$query = $this->db->get('uploads', $count, $start);
return $query->result();
}
} }
?> ?>

View file

@ -0,0 +1,9 @@
<?php echo $pagination; ?>
<div id="imageContainer" style="width: 960px;margin: auto;">
<?php foreach($uploads as $upload) { ?>
<div id="galleryContainer">
<img src="<?php echo base_url('/thumbs/' . $upload->id . $upload->extension); ?>" />
</div>
<?php } ?>
</div>

View file

@ -262,6 +262,7 @@ h1{
--------------------------*/ --------------------------*/
#left { #left {
position: absolute; position: absolute;
left: 0; left: 0;
@ -285,3 +286,20 @@ h1{
height: 50px; height: 50px;
width: 50px; width: 50px;
} }
/*-------------------------
Gallery
--------------------------*/
#galleryContainer {
width: 175px;
height: 175px;
float: left;
margin: 5px;
position: relative;
text-align: center;
}