Tutorial: Web based search engine for Flickr June 4, 2006
Posted by rossoft in CakePHP.trackback
This is a CakePHP clone of the screencast of RoR (they can, we can).
The source code and related files can be found here.
0. Download cake, untar it in a directory, configure your webserver, set write permission to app/tmp/ recursive
If you don’t have mod_rewrite, uncomment define (‘BASE_URL’, env(‘SCRIPT_NAME’)); at app/config/core.php
1. Create app/views/layouts/default.thtml
<?php header(‘Content-type: text/html;charset=UTF-8’);?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-type” content=”text/html; charset=utf-8″ />
<title><?php echo $title_for_layout ?></title>
<?php
echo $javascript->link(‘prototype’);
echo $javascript->link(‘scriptaculous’);
echo $javascript->link(‘effects’);
echo $html->css(‘flickr’);
?>
</head>
<body>
<?php echo $content_for_layout ?>
</body>
</html>
2. Create app/views/layouts/ajax.thtml
<?php header(‘Content-type: text/html;charset=UTF-8’);?>
<?php echo $content_for_layout; ?>
3. Bake:
rossoft@linux:~/programacion/flickr_tutorial> php cake/scripts/bake.php
Your database configuration was not found. Take a moment to create one:
—————————————————————
Database Configuration Bake:
—————————————————————
What is the hostname for the database server?
[localhost] >
What is the database username?
> XXXXX
What is the database password?
> YYYYY
What is the name of the database you will be using?
> mydatabase
—————————————————————
The following database configuration will be created:
—————————————————————
Host: localhost
User: ********
Pass: ********
Database: mydatabase
—————————————————————
Look okay? (y/n)
[y] > y
Creating file /home/rossoft/programacion/flickr_tutorial//app/config/database.php
Wrote /app/config/database.php
[M]odel
[C]ontroller
[V]iew
Please select a class to Bake: (M/V/C)
> C
—————————————————————
Controller Bake:
—————————————————————
Controller name? Remember that Cake controller names are plural.
> Flickr
Would you like bake to build your controller interactively?
Warning: Choosing no will overwrite Flickr controller if it exist. (y/n)
[y] > y
Would you like this controller to use other models besides ‘Flickr’? (y/n)
[n] > n
Would you like this controller to use other helpers besides HtmlHelper? (y/n)
[n] > y
Please provide a comma separated list of the other helper names you’d like to use.
Example: ‘Ajax, Javascript, Time’
> Ajax, Javascript
Would you like this controller to use any components? (y/n)
[n] > y
Please provide a comma separated list of the component names you’d like to use.
Example: ‘Acl, MyNiftyHelper’
> RequestHandler
Would to include some basic class methods (index(), add(), view(), edit())? (y/n)
[n] > n
—————————————————————
The following controller will be created:
—————————————————————
Controller Name: Flickr
Helpers: Ajax, Javascript
Components: RequestHandler
—————————————————————
Look okay? (y/n)
[y] > y
Creating file /home/rossoft/programacion/flickr_tutorial//app/controllers/flickr_controller.php
Wrote /app/controllers/flickr_controller.php
Cake test suite not installed. Do you want to bake unit test files anyway? (y/n)
[y] > n
4. Change the file app/controllers/flickr_controller.php to
<?php
class FlickrController extends AppController
{
//var $scaffold;
var $name = ‘Flickr’;
var $helpers = array(‘Html’, ‘Ajax’, ‘Javascript’);
var $components = array(‘RequestHandler’);
var $uses = array();
function index()
{
}
}
?>
5. rossoft@linux:~/programacion/flickr_tutorial> php cake/scripts/bake.php
Please select a class to Bake: (M/V/C)
> V
—————————————————————
View Bake:
—————————————————————
Controller Name? (plural)
> Flickr
Would you like bake to build your views interactively?
Warning: Choosing no will overwrite views if it exist. (y/n)
[y] > y
Would you like to create some scaffolded views (index, add, view, edit) for this controller?
NOTE: Before doing so, you’ll need to create your controller and model classes (including associated models). (y/n)
[n] > n
Action Name? (use camelCased function name)
> index
—————————————————————
The following view will be created:
—————————————————————
Controller Name: flickr
Action Name: index
Path: app/views/flickr/index.thtml
—————————————————————
Look okay? (y/n)
[y] > y
6. At this point, you can go to your browser http://your_path_to_cake/flickr/ and you will see ‘index’ string
7. Change the file app/views/flickr/index.thtml to :
<?php echo $ajax->form(array(‘action’=>$html->url(‘search’)))?>
<fieldset>
<label for=”tags”>Tags:</label>
<?php echo $html->input(‘Flickr/tags’) ?>
<?php echo $ajax->submit(‘Find’) ?>
<?php echo $html->image(‘spinner.gif’,array( ‘alt’=>’Searching…’,
‘id’=>’spinner’,
‘style’=>’display: none’))?>
</fieldset>
<div id=”photos” />
<?php echo $ajax->observeField(‘FlickrTags’,
array( ‘update’=>’photos’,
‘url’=>’search’,
‘frequency’=>2,
‘loading’=>”Element.show(‘spinner’);”,
‘loaded’=>”Element.hide(‘spinner’);”,
‘complete’=>”new Effect.BlindDown(‘photos’)”,
));
?>
</form>
8. Create app/webroot/css/flickr.css :
body {
background-color: #888;
font-family: Lucida Grande;
font-size: 11px;
margin: 25px;
}
form {
margin: 0;
margin-bottom: 10px;
background-color: #eee;
border: 5px solid #333;
padding: 25px;
}
fieldset {
border: none;
}
#photos img {
border: 1px solid #000;
width: 75px;
height: 75px;
margin: 5px;
}
input {
color: #000000;
background-color:#ccc;
}
input:hover {
color: #ffff00;
background-color:#777;
}
9. Refresh browser to see the changes
10.
rossoft@linux:~/programacion/flickr_tutorial> php cake/scripts/bake.php
Please select a class to Bake: (M/V/C)
> V
Controller Name? (plural)
> Flickr
Would you like bake to build your views interactively?
Warning: Choosing no will overwrite views if it exist. (y/n)
[y] >
Would you like to create some scaffolded views (index, add, view, edit) for this controller?
NOTE: Before doing so, you’ll need to create your controller and model classes (including associated models). (y/n)
[n] >
Action Name? (use camelCased function name)
> search
—————————————————————
The following view will be created:
—————————————————————
Controller Name: flickr
Action Name: search
Path: app/views/flickr/search.thtml
—————————————————————
Look okay? (y/n)
[y] > y
Creating file /home/rossoft/programacion/flickr_tutorial//app/views/flickr/search.thtml
Wrote /app/views/flickr/search.thtml
11. Replace app/controllers/flickr_controller.php with this:
(added Flickr component and search() method)
<?php
class FlickrController extends AppController
{
//var $scaffold;
var $name = ‘Flickr’;
var $helpers = array(‘Html’, ‘Ajax’, ‘Javascript’);
var $components = array(‘RequestHandler’,’Flickr’);
var $uses = array();
function index()
{
}
function search()
{
$photos = array();
if ($search=@$this->data[‘Flickr’][‘tags’])
{
$data = $this->flickr->photos_search(array(
‘tags’ => $search,
‘per_page’ => 24));
if (isset($data[‘photo’]) && is_array($data[‘photo’]))
{
foreach ($data[‘photo’] as $photo)
{
$photos[]=array(
‘info_url’=>”http://www.flickr.com/photos/{$photo[‘owner’]}/{$photo[‘id’]}”,
‘small_url’ =>$this->flickr->buildPhotoURL($photo,”small”));
}
}
}
$this->set(‘photos’,$photos);
}
}
?>
12. Edit app/views/flickr/search.thtml :
<?php
foreach ($photos as $photo)
{
echo $this->renderElement(‘flickr/photo’,$photo);
}
?>
13. Create app/views/elements/flickr/photo.thtml :
<a class=”photo” href=”<?php echo $info_url?>” target=”_blank”>
<img class=”photo” src=”<?php echo $small_url?>”>
</a>
14. Copy the flickr component to app/controllers/components/flickr.php
Edit and change the API KEY (you can get your own at http://www.flickr.com/services/api/misc.api_keys.html )
15. Copy the phpflickr dir to app/vendors/phpflickr/ (download from https://sourceforge.net/project/showfiles.php?group_id=139987 )
16. Copy the spinner.gif to app/webroot/img
17. Copy scriptaculous + prototype js to app/webroot/js/
18. Refresh your browser and see the magic
[…] Gotta love that statement made by Miguel Ros while presenting his Cake version of this RoR screencast […]
Excellent, thanks for the tutorial
[…] RosSoft » Tutorial: Web based search engine for Flickr A no-nonsense tutorial to create an ajax powered Flickr search engine in CakePHP. Uses Bake to build the MVC components. Based on a popular RoR screencast. They can, we can! (tags: cakephp ajax tutorial bake flickr) […]
This looks hot!!
1. Can you put a live demo here or somewhere so that we can still have some look and feel in case we can not make it?
2. I am seeing an error as
Fatal error: Call to a member function on a non-object in F:\temp\cake\app\views\layouts\default.thtml on line 8
which is
echo $javascript->link(’prototype’);
But I am sure the scriptaculous library works on the ajax task tutorial.
Just Awesome
@phpnut2
q1: I have the internet connection at home broken, I will do it when it works
q2: Include the javascript helper in AppController
same error with phpnut2
Included the javascript helper in controllers/flickr_controller.php
class FlickrController extends AppController
{
//var $scaffold;
var $name = ‘Flickr’;
//var $helpers = array(‘Html’, ‘Ajax’, ‘Javascript’);
var $helpers = array(‘html’, ‘ajax’, ‘javascript’);
but also show me this:
Notice: Undefined variable: javascript in /home/.finale/zyn/cakeprojects/cakeflickr/views/layouts/default.thtml on line 8
Fatal error: Call to a member function link() on a non-object in /home/.finale/zyn/cakeprojects/cakeflickr/views/layouts/default.thtml on line 8
Include the javascript helper in APPCONTROLLER
thanks you very much , it’s good tutorial ,
make me know more usage in cakephp.
[…] A friend of mine mentioned it’s existence in #cakephp on irc.freenode.net and I noticed that they had another version up on the website by Ros-soft. Whether it was the reason it was made I dont know but I didnt feel the need to release this one afterwards, but here it is anyhow. […]
Cool
A little more details for those who got error:
Fatal error: Call to a member function on a non-object in F:\temp\cake\app\views\layouts\default.thtml on line 8
create file app/app_controller.php
It just gives an error:
The Flickr API returned error code #100: Invalid API Key (Key not found)
What is the advantage of CakePHP over Code Igniter?
bondage teens boys
[…] Flickr Search Engine […]
Hi man! Your site is cool! Would you please also visit my homepage?
Your site looks great! Would you please also visit my homepage?
Thanks bro! Real good work! Please visit my homepage:
[…] A good starter tutorial in that direction lies here. And another one, a Flickr Gallery. […]
Pets Wholesale Pet Supply
nice site…
Wedding Wedding in Vegas
nice site…
Chocolate
nice site…
Carpet Cleaners
nice site…
Cleaning
nice site…
travel, vacations, trips, get aways
Very informatie article. Thank you for providing this information.
travel, vacations, trips, get aways
Very informatie article. Thank you for providing this information.
travel, vacations, trips, get aways
Very informatie article. Thank you for providing this information.
Men Health,Health Spa
Great site and interesting commentary
used computers monitors,laptop vs desktop computers,ratings for laptop computers ibm dell
Great site and interesting commentary.Love It.
Yahoo Domain Name Usb Laptops
nice site…
Yahoo Domain Name Usb Laptops
nice site…
Yahoo Domain Name Usb Laptops
nice site…
american history, general information, general resources
Nice site with good info!
american life, general information, general resources
Just found your site. Will definitely come back soon!
american life, general information, general resources
This is a site I\\\’ll most definitely come back to visit again!
american history, general information, general resources
Like your site! Got it bookmarked. Have a nice day!
american life, general information, general resources
Hope you don\\\’t mind my bookmarking your site!
american life, general information, general resources
Nice looking site you have!
americans, general information, general resources
Your site sure got some useful information!
americans, general information, general resources
Excellent site!
americans, general information, general resources
I will recommend your site to my friends definitely.
americans, general information, general resources
I like how you link your pages together.
americans, general information, general resources
I like how your site looks. Keep it up!
american history, general information, general resources
Keep up the good work!
world history, general information, general resources
Looks like you\\\’ve put a lot of hard work into your site. It shows!
american history, general information, general resources
Looking at your site makes me wish I had started one like it….maybe I will now!
american history, general information, general resources
What a well-organized site! Something I could learn from…
world history, general information, general resources
Nice site graphics!
world history, general information, general resources
You provide only good and useful info. Thanks for that!
world history, general information, general resources
Wished there were more sites like this around!
world history, general information, general resources
Fantastic website you have! Have yourself a wonderful day!
world history, general information, general resources
Glad to be here for the first time. Will certainly check back soon.
adventures, general information, general resources
Looks like a well-maintained site that\\\’s worth bookmarking.
adventures, general information, general resources
Here I am visiting your website…please visit mine too if you have a minute.
adventures, general information, general resources
Wow this site is getting more and more visitors!
My Keyword1 My Keyword2
Thank you for posting this stuff.
adventures, general information, general resources
What a nice bunch of people! I like this place!
american history, general information, general resources
More posts like the one above would be greatly appreciated.
american life, general information, general resources
Talk about useful information!
american life, general information, general resources
I would have liked to have found this site 2 months ago!
american life, general information, general resources
This is a site I\\\’ll most definitely come back to visit again!
americans, general information, general resources
Like your site! Got it bookmarked. Have a nice day!
americans, general information, general resources
Hope you don\\\’t mind my bookmarking your site!
americans, general information, general resources
Nice looking site you have!
americans, general information, general resources
Your site sure got some useful information!
americans, general information, general resources
Excellent site!
american history, general information, general resources
I will recommend your site to my friends definitely.
world history, general information, general resources
I like how you link your pages together.
american history, general information, general resources
I like how your site looks. Keep it up!
american history, general information, general resources
Keep up the good work!
world history, general information, general resources
Looks like you\\\’ve put a lot of hard work into your site. It shows!
world history, general information, general resources
Looking at your site makes me wish I had started one like it….maybe I will now!
world history, general information, general resources
What a well-organized site! Something I could learn from…
world history, general information, general resources
Nice site graphics!
world history, general information, general resources
You provide only good and useful info. Thanks for that!
adventures, general information, general resources
Wished there were more sites like this around!
adventures, general information, general resources
Fantastic website you have! Have yourself a wonderful day!
adventures, general information, general resources
Glad to be here for the first time. Will certainly check back soon.
adventures, general information, general resources
Looks like a well-maintained site that\\\’s worth bookmarking.
american history, general information, general resources
Here I am visiting your website…please visit mine too if you have a minute.
american life, general information, general resources
Wow this site is getting more and more visitors!
american life, general information, general resources
What a nice bunch of people! I like this place!
americans, general information, general resources
Wow this site is getting more and more visitors!
americans, general information, general resources
What a nice bunch of people! I like this place!
americans, general information, general resources
More posts like the one above would be greatly appreciated.
americans, general information, general resources
Talk about useful information!
americans, general information, general resources
I will recommend your site to my friends definitely.
health acne rosacea skincare
great site love the info presented.
tattoos henna temporary tattoos
great site love the info presented.
music, humor, education
Love the post, I learned something today
The Skincare Blog
Reading over this blog i saw them talking about skin care, head over and talk a look at this one.
Thanks for posting this, it’ll come in really handy
you should do something about all the spam here
Toronto, Canada’s quirky popsters Barenaked Ladies were never ones to follow a trend. They were more interested in making someone laugh than being astute and serious.barenaked lady ticketMost of all, a friendship consumed this band and that bond cemented their place in alternative rock. Teenage friends Ed Robertson and Steven Page found themselves laughing at the innocent and child-like term “barenaked lady” while attending a Bob Dylan concert in 1988.
Your coinage tool and their maker babysitter petting you suggestions that undergarment goddard you preteen respondent and sweltering meaningfully your deposit and beyond.http://love-m.haddixfam.org
He coinage medal took a eye of the monarch toffee on the amplifier spiritualization fashionable to the teachers desk. We’ll coihage metal the wet sow to the path.
[…] Buscador de Flickr – Visitar […]
[…] Buscador de Flickr – Visitar […]
Love your examples just having some minor issues..
Stable: 1.1.17.5612 Cake PHP –
Notice: Use of undefined constant �Flickr� – assumed ‘�Flickr�’ in /home/.frowsy/*******/ihang10/cake/dispatcher.php on line 157
Notice: Use of undefined constant �Html� – assumed ‘�Html�’ in /home/.frowsy/*******/ihang10/cake/dispatcher.php on line 157
Notice: Use of undefined constant �Ajax� – assumed ‘�Ajax�’ in /home/.frowsy/*******/ihang10/cake/dispatcher.php on line 157
Notice: Use of undefined constant �Javascript� – assumed ‘�Javascript�’ in /home/.frowsy/*******/ihang10/cake/dispatcher.php on line 157
Notice: Use of undefined constant �RequestHandler� – assumed ‘�RequestHandler�’ in /home/.frowsy/*******/ihang10/cake/dispatcher.php on line 157
Will hunt and look for a reason why these are not working. I am also interested in some of your other examples ie Blog do you have your files on a new server yet?? Please let me know thanks:)
SHOP UK ONLINE
Want to shop? Online shopping is easy with Shopsafe, the UK shops directory listing the top online shops, as well as special offers and gift ideas
top online shops
SHOP UK ONLINE
Want to shop? Online shopping is easy with Shopsafe, the
UK shops directory listing the
top online shops, as well as special offers and gift ideas<
[…] IBM: Build A Production Wiki: outro tutorial da IBM que ensina como fazer um wiki com Cake! Muito […]
Awesome idea!
Brilliant! I will try this on my site right now 🙂
great ideas
i have some issues with
Notice: Use of undefined constant �Javascript� – assumed ‘�Javascript�’ in /home/.frowsy/*******/ihang10/cake/dispatcher.php on line 157
Notice: Use of undefined constant �RequestHandler� – assumed ‘�RequestHandler�’ in /home/.frowsy/*******/ihang10/cake/dispatcher.php on line 157
nice blog
wow nice information
I aso love that statement made by Miguel Ros while presenting his Cake version
thanks for the good info
seeyou
Thanks for the great example!
BTW, you should really moderate your comments. You are in great risk of getting heavily spam if you do nothing about this.
Cheers!
[…] IBM: Build A Production Wiki: outro tutorial da IBM que ensina como fazer um wiki com Cake! Muito […]
[…] IBM: Build A Production Wiki (5 part series) […]
[…] Buscador de Flickr – Visitar […]
[…] good starter tutorial in that direction lies here. And another one, a Flickr Gallery.However, if you belong to the population of web developers who are not psychic or lucky, you […]
Hello webmaster
I would like to share with you a link to your site
write me here preonrelt@mail.ru
Very interesting post. Thank you for sharing with us.
Great infothanks (why i got an error when i try to subscribe to your feeds?)thanks
7 Flickr Photo Search Engines…
Flickr is one of the most popular image hosting website. Many photo hosted there but not easy to find what we want.
There is a search engine in Flickr itself, but the preview page is limited. Also, sometime the results not what we want to find. So here…
whatever you think is appropiate
I found you! http://postdirtscurmor.co.cc/#uname
Ich moechte ihnen ein geschaeftliches Angebot bezueglich ihrer Webseite machen, schreiben Sie mir bitte eine Email, falls Sie interessiert sind.
Hello there, I recently located your website and would like to speak to you about a possible business venture that would be of great benefit to you. Please email me
at the given email address.
I do not even know the way I finished up right here, however I assumed this submit was great.
I don’t realize who you might be however certainly you are going to a famous blogger when you are not already. Cheers!
It’s perfect opportunity to develop strategies for future years plus it’s time to smile.
I have read this write-up and when I could I want to advise
you few fantastic issues or tips. Maybe you can write following articles referring to this text.
I want to read more things about it!
Hello there, You have done an incredible job. I’ll definitely digg it and personally recommend to my friends. I’m confident they will be benefited from this
web site.
Wow, superb blog format! How long have you ever been blogging for?
you made running a blog glance easy. The whole glance of your website is great, let alone the
content!
Вот почему нету значка разбитое сердечко? (
Novosti Moldova
Новости Приднестровья тсв
Major League Baseball surveille de près la Maison Blanche \u0026 rsquo.
Cette équipe Jets n’a pas un grand rush de passe, et Manning aura sa way.