• About Me




    Lily@Melbourne, Australia

    Login

  • Follow 静水深流 || Still waters run deep on WordPress.com
  • Archives

CakePHP-Flickr

首先得感谢Duke,由于他的帮助,我只花了半个多小时就搞定了相册。

据说搜索‘cakephp + flickr’,最后所有的连接指向一个结果:http://www.sitepoint.com/photo-gallery-cakephp-flickr/,而这个根本工作不了的。:(

同样MVC的构架,但这次只有VC

Controller:

var $uses = null; //不用DB

View:

 

//link jquery.js and lightbox.js, lightbox.css以及lightbox所带的icons.

$url = 'http://api.flickr.com/services/rest/?&method=flickr.photosets.getPhotos&api_key=1234&photoset_id=1234&format=json&nojsoncallback=1';//apikey 从flickr获得,而photoset就是你想公开发布的相册名

$json = file_get_contents($url);

$object = json_decode( $json );

$pictureId = $object->photoset->photo;

foreach ($pictureId as $photoInfor ){

echo "<a href='http://farm".$photoInfor->farm.".staticflickr.com/".$photoInfor->server."/".$photoInfor->id."_".$photoInfor->secret.".jpg' rel='lightbox[breadRoll]'' title='".$photoInfor->title."'> <img src=http://farm".$photoInfor->farm.".staticflickr.com/".$photoInfor->server."/".$photoInfor->id."_".$photoInfor->secret.".jpg width=150 height=150 rel=lightbox > </a>";

}

效果

Gallery

Gallery

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: