It’s been a while, but I’ve finally made the plunge and did the first in the series of cookbook-related screencast tutorials for Symfony.
Edit: here’s the gist of the video.
== The sfFinder class ==
Symfony comes bundled with the sfFinder
class that lets you conveniently search for files and directories. It has a simple fluent interface that lets you tell what you’re looking for and where to look for it:
sfFinder::type('file')->name('*.jpg')->in(sfConfig::get('sf_upload_dir'));
To illustrate this example, let’s use an action that lists the contents of the upload folder. Inside an action, we assign the array returned by sfFinder
to the template:
$this->images = sfFinder::type('file')->name('*.jpg')->relative()->in(sfConfig::get('sf_upload_dir'));
Since, by default, sfFinder
returns absolute paths, we tell it to return everything relative to the search directory – this will include subdirectories as well.
In a template, we can now iterate over the images to list them:
foreach($images as $image):
echo '<li>' . image_tag('/uploads/' . $image); . '</li>';
endforeach;
Nice initiative, it’s fun and efficient
Comment by NiKo — June 22, 2008 @ 7:08 am
and short
. This is very important, because I rarely watch a video over 1min long.
Comment by gasper_k — June 22, 2008 @ 10:55 am
Yeah, I wanted to avoid being long-winded. Nobody has time for long tutorials – it’s mostly “I have a task to perform, not learn how to operate a concrete mixer truck.”
Comment by Krof Drakula — June 22, 2008 @ 11:03 am
But, come to think about it, this would be way more efficient in a form of one-liner and two screenshots. It is a one-liner and two screenshots (before and after), maybe three (a screenshot of the directory), would be quite enough.
Comment by gasper_k — June 22, 2008 @ 12:34 pm
True, but where’s the Web-2.0-ishness in that?
It’s all about who’s got the screencasts and who doesn’t.
Comment by Krof Drakula — June 22, 2008 @ 1:13 pm
… no matter the productivity, eh? You lose your time making the screencast, we lose ours watching it, and the work gets done itself.
But honestly, sometimes I prefer the old way. I hate funny pics slideshow glued together in a video … Give a document where I can click only those that seem interesting.
Comment by gasper_k — June 22, 2008 @ 7:24 pm
Funny though, it got more traffic than any of my previously outlined posts.
But there is merit to have it transcribed, at least is SEO terms if not for usability – I’ll include the transcript and code with screenshots next time.
Comment by Krof Drakula — June 22, 2008 @ 9:13 pm
yay!
Comment by gasper_k — June 23, 2008 @ 8:34 am
nice work
Comment by Chat — August 22, 2008 @ 2:38 pm
This is very nice post. thank you. i love
Comment by Web Tasarım Ankara — December 5, 2008 @ 5:22 pm
It is difficult to find support for some stuff on this planet and symphony is one of that. I am wondering why this blog was hidden to me but I am happy to find it now.
Comment by Iamsgf@Flights to Australia — December 19, 2008 @ 4:57 am
It is difficult to find support for some stuff on this planet and symphony is one of that.
Comment by web tasarımı — February 6, 2009 @ 12:53 am
I am wondering why this blog was hidden to me but I am happy to find it now.
Comment by Cappadocia — May 20, 2009 @ 1:07 pm
Nice and informative blog
Comment by José Santos — May 27, 2009 @ 1:16 am
Wow! Interesting technique. Thanks for the tutorial.
Comment by Hamming — July 21, 2009 @ 5:55 am
YASB – Yet Another Symfony Blog » Blog Archive » A Symfony Quickie: Finding a File great article thank you.
Comment by moto kurye — August 20, 2009 @ 6:47 pm
YASB – Yet Another Symfony Blog » Blog Archive » A Symfony Quickie: Finding a File great article thank you.
Comment by web tasarım — August 20, 2009 @ 8:24 pm
Thanks a lot for this useful post, the info is pretty good and the desciption very adecuate. Keep the good work. The video support is excellent.
jugar poker
Comment by Sean — September 14, 2009 @ 10:56 pm
Neat tutorial vid! I’ve been using Symfony for a few years now and never knew about the file finder.
Comment by Matthew — October 19, 2009 @ 6:10 am
This is very nice post. thank you.
Comment by diziizleyelim — November 17, 2009 @ 4:31 am
Great work
Comment by Annika — February 9, 2010 @ 1:20 pm
Thanks for the tips. For french speaking poeple, I propose a link to learn Symfony : http://blog.jaycreation.net/post/Tutoriel-Symfony-L-aide-indispensable-a-la-creation-d-une-application-Symfony
Comment by jaycreation — July 2, 2010 @ 5:42 pm
Nice video. It is a very short video tutorial. Using this Symfony Quickie for finding files is a great idea.
Comment by Chad Wilson — August 13, 2010 @ 7:57 am
thanks.
Comment by matbaa — August 18, 2010 @ 9:18 am