Nemogu da objašnjavam, ovo sam davno nešto škrabao. U suštini proslediš array u template...
http://en.wikipedia.org/wiki/Model%E...0%93controller
PHP kôd:
class View {
public static function factory($file, array $array)
{
extract($array, EXTR_SKIP);
ob_start();
include $file.'.php';
return ob_get_clean();
}
public static function render()
{
global $html;
$content = &$html;
ob_start();
include 'views/template.php';
echo ob_get_clean();
return true;
}
}
PHP kôd:
$date = date('dmY', time());
$file = ".cache/gallery/{$date}.json";
if(file_exists($file) === true)
{
$json = file_get_contents($file);
}
else
{
$json = curl('https://graph.facebook.com/'.$id.'/photos?limit=200&offset=0&access_token='.$token);
file_put_contents($file, $json);
}
$json = json_decode($json, true);
foreach($json['data'] as $photo)
{
$gallery .= View::factory('views/gallery/photo', array('photo' => $photo));
}
$html .= View::factory('views/gallery/index', array('gallery' => $gallery));
View::render();
photo.php
PHP kôd:
<a href="<?=$photo['source']?>" class="modal" rel="foto"><img alt="" src="<?=$photo['images'][1]['source']?>"/></a>