Skip to content

Instantly share code, notes, and snippets.

@nicekiwi
Created October 22, 2012 10:47
Show Gist options
  • Save nicekiwi/3930914 to your computer and use it in GitHub Desktop.
Save nicekiwi/3930914 to your computer and use it in GitHub Desktop.
presenter photos thing
<?php // my view ?>
<h1><?php echo $album_info['0']['album_name'] ?></h1>
<a href="/photos/<?php echo $album_info['0']['album_year'] ?>" title="Back to Albums">Back to Albums</a>
<ul class="photo-items">
<?php foreach($album_photos as $k => $v) {$album_photos[$k] = (object) $v;} ?>
<?php $album_presenter->partial('list_photos'); ?>
</ul>
<div class="top_link"><a class="smooth_ride" href="<?php $_SERVER['REQUEST_URI'] ?>#top">Back to top</a></div>
<?php // presenter
class Album_presenter extends Presenter {
public $v_map = array(
'class' => array('photo_width', 'photo_height'),
'url' => array('photo_link'),
);
public function transform_photo_link($url)
{
return substr($url,0,-5);
}
public function transform_class($width, $height)
{
if($height > 250){$class = 'vertical';}else if($height < 160){$class = 'smaller';}else{$class = '';}
if($width < 240){$class .= ' thin';}
return $class;
}
public function transform_url($url)
{
$url = explode('/',$url);
return substr($url[4],0,-6);
//return 'meow';
}
}
<?php //my partial thing, located in partials/album/list_photos.php ?>
<li>
<div class="thumbBox">
<div class="thumb photo">
<a href="#photo_link#n.jpg" class="fancybox" title="">
<img class="lazy" data-original="/uploads/images/photos/#url#.jpg" alt="" width="240" />
</a>
</div>
</div>
</li>
$album = ('photo_id'=>'', 'album_id'=>'', 'photo_link'=>'', 'photo_link_hr'=>'', 'photo_link_fb'=>'', 'photo_width'=>'', 'photo_height'=>'', 'photo_auth'=>'', 'photo_da'=>'', 'photo_du'=>'');
<?php // controller method ?>
public function album($album_slug)
{
// Somehow THIS array also needs to get into the partial loop.
$data['album_info'] = $this->photos_model->get_album_info($album_slug);
if (empty($data['album_info']))
{
show_404();
}
// main photos array
$album = $this->photos_model->get_album($data['album_info']['0']['album_id']);
if (empty($album))
{
show_404();
}
$data['title'] = $data['album_info']['0']['album_name'];
$data['album_presenter'] = $this->presenter->create('album', $album);
$this->load->view('templates/header', $data);
$this->load->view('photos/album', $data);
$this->load->view('templates/footer');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment