<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://mirmodynamics.com/feed/rss2/xslt" ?><rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
  <title>Mirmo Dynamics - Tag - tips</title>
  <link>http://mirmodynamics.com/</link>
  <atom:link href="http://mirmodynamics.com/feed/tag/tips/rss2" rel="self" type="application/rss+xml"/>
  <description>Si tu kiffes pas reunoi, t'écoutes pas et puis c'est tout.</description>
  <language>en</language>
  <pubDate>Sun, 14 Mar 2010 19:59:01 +0100</pubDate>
  <copyright>2003-2009 &amp;copy; Geoffrey Bachelet</copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
  <item>
    <title>Dynamic directory with sfValidatorFile</title>
    <link>http://mirmodynamics.com/post/2009/10/14/Dynamic-directory-with-sfValidatorFile</link>
    <guid isPermaLink="false">urn:md5:0b3f55753dc88911b8afa1fcdfdf4882</guid>
    <pubDate>Wed, 14 Oct 2009 23:22:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Symfony</category>
        <category>directory</category><category>form</category><category>sfForm</category><category>sfValidatorFile</category><category>symfony</category><category>tips</category><category>upload</category>    
    <description>    &lt;p&gt;Say you have a form with a file upload (field &lt;code&gt;image&lt;/code&gt; of your model for example), and that you want to save your file in a directory depending on its filename. For example, the file &lt;code&gt;foobar.jpg&lt;/code&gt; shall be stored in &lt;code&gt;fo/ob/foobar.jpg&lt;/code&gt;. All you have to do is implement a &lt;code&gt;generateImageFilename&lt;/code&gt; method in your model:&lt;/p&gt;

&lt;pre&gt;
  public function generateImageFilename(sfValidatedFile $file)
  {
    $filename = $file-&amp;gt;generateFilename();
    return sprintf('%s/%s/%s', substr($filename, 0, 2), substr($filename, 1, 2), $filename);
  }
&lt;/pre&gt;


&lt;p&gt;And voila !&lt;/p&gt;


&lt;p&gt;For more information on what's happening there, see &lt;code&gt;sfFormDoctrine::saveFile()&lt;/code&gt; (around line 510 of &lt;code&gt;plugins/sfDoctrinePlugin/lib/form//sfFormDoctrine.class.php&lt;/code&gt;)&lt;/p&gt;</description>
    
    
    
          <comments>http://mirmodynamics.com/post/2009/10/14/Dynamic-directory-with-sfValidatorFile#comment-form</comments>
      <wfw:comment>http://mirmodynamics.com/post/2009/10/14/Dynamic-directory-with-sfValidatorFile#comment-form</wfw:comment>
      <wfw:commentRss>http://mirmodynamics.com/feed/atom/comments/1201</wfw:commentRss>
      </item>
    
  <item>
    <title>Rebooting the iphone without touching the screen</title>
    <link>http://mirmodynamics.com/post/2008/12/26/Rebooting-the-iphone-without-touching-the-screen</link>
    <guid isPermaLink="false">urn:md5:1c8f75eb7d4104554af24947b2b42d2e</guid>
    <pubDate>Fri, 26 Dec 2008 11:46:00 +0100</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Geekeries</category>
        <category>bug</category><category>iphone</category><category>tips</category>    
    <description>    &lt;p&gt;Yesterday, I had a bug with my iphone that prevented me to use the touchscreen. Weird. &lt;em&gt;No problem&lt;/em&gt; I though, &lt;em&gt;I'll just reboot the damn thing and it'll be fine&lt;/em&gt;. Except you need the touch screen to turn the iPhone off. After a few manipulation and frustration, I found out that you can actually reboot the iphone by holding the &lt;em&gt;power button&lt;/em&gt; and &lt;em&gt;main button&lt;/em&gt; simultaneously for a few seconds. Handy heh.&lt;/p&gt;</description>
    
    
    
          <comments>http://mirmodynamics.com/post/2008/12/26/Rebooting-the-iphone-without-touching-the-screen#comment-form</comments>
      <wfw:comment>http://mirmodynamics.com/post/2008/12/26/Rebooting-the-iphone-without-touching-the-screen#comment-form</wfw:comment>
      <wfw:commentRss>http://mirmodynamics.com/feed/atom/comments/1164</wfw:commentRss>
      </item>
    
  <item>
    <title>Passing arbitrary parameters to a route in symfony</title>
    <link>http://mirmodynamics.com/post/2008/11/02/Passing-arbitrary-parameters-to-a-route-in-symfony</link>
    <guid isPermaLink="false">urn:md5:7954eb5f9f623e4d1fcd8829f2d32adb</guid>
    <pubDate>Sun, 02 Nov 2008 21:12:00 +0100</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Symfony</category>
        <category>handy</category><category>parameters</category><category>routing</category><category>symfony</category><category>tips</category>    
    <description>    &lt;p&gt;Parameters are an important parts of routes in symfony, and in any other routing framework for that matter, and everyone knows how to add mandatory or optional parameters to a route. But did you know you can also silently pass arbitrary parameters to a route from the routing definitions ? This may not be a very clear description, so let's take an example. Say you have a tabbed navigation system, and you want to know in your template which tab is the current one. In a perfect world, you could assume one tab corresponds to a module and check this module, but let's say that one tab can contain multiples modules. How are you doing now ? Quite simply actually, by passing a &lt;code&gt;tab&lt;/code&gt; parameter to your route.&lt;/p&gt;

&lt;pre&gt;
foo_route:
  url:       /foo
  param: { tab: foobar }

bar_route:
  url:       /bar
  param: { tab: foobar }
&lt;/pre&gt;


&lt;p&gt;Now you can access the tab parameter in your layout:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;?php $currentTab = $sf_params-&amp;gt;get('tab'); ?&amp;gt;
&lt;/pre&gt;


&lt;p&gt;Easy heh ? Of course this kind of parameters is not limited to tell which tab we're currently in, you can, for example, bypass the limitation of a system that requires a particular file to be in a particular location (not that using mod_rewrite would not be more efficient, I just wanted one more example):&lt;/p&gt;

&lt;pre&gt;
foobar_xml:
  url:       /a/stupid/url/that/you/cant/change/foobar.xml
  param: { module: default, action: static, file: &amp;quot;/assets/foobar.xml&amp;quot;, mimetype: &amp;quot;text/xml&amp;quot; }
&lt;/pre&gt;


&lt;p&gt;Here we simply pass the &lt;code&gt;file&lt;/code&gt; and &lt;code&gt;mimetype&lt;/code&gt; parameters to an action that'll take care to serve the right file.&lt;/p&gt;


&lt;p&gt;Handy ! But please note that you can't pass such parameters in &lt;code&gt;sfPropelRouteCollection&lt;/code&gt; for now (yup, this a bug, and there's a ticket already).&lt;/p&gt;</description>
    
    
    
          <comments>http://mirmodynamics.com/post/2008/11/02/Passing-arbitrary-parameters-to-a-route-in-symfony#comment-form</comments>
      <wfw:comment>http://mirmodynamics.com/post/2008/11/02/Passing-arbitrary-parameters-to-a-route-in-symfony#comment-form</wfw:comment>
      <wfw:commentRss>http://mirmodynamics.com/feed/atom/comments/1150</wfw:commentRss>
      </item>
    
  <item>
    <title>Mass vim file opening reloaded</title>
    <link>http://mirmodynamics.com/post/2008/10/16/Mass-vim-file-opening-reloaded</link>
    <guid isPermaLink="false">urn:md5:043b3c3596084fc127d581eb3ee0bb15</guid>
    <pubDate>Thu, 16 Oct 2008 21:20:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Geekeries</category>
        <category>bash</category><category>grep</category><category>handy</category><category>script</category><category>tips</category><category>vim</category>    
    <description>    &lt;p&gt;Thinking about it, &lt;a href=&quot;http://mirmodynamics.com/post/2008/10/14/Mass-vim-file-opening&quot;&gt;the snippet I posted earlier&lt;/a&gt; was a bit silly as vim can open by itself multiple files way more efficiently. The only benefit from my script is that I don't have to type the &lt;code&gt;--servername&lt;/code&gt; and &lt;code&gt;--remote-silent-tab&lt;/code&gt;.&lt;/p&gt;


&lt;p&gt;So let's add some usefulness ! First, when I need this script, it's often that I first grepped the files, and then decide that I want to edit them all. From this point of view, having to pass them as &lt;em&gt;arguments&lt;/em&gt; is not that handy, so we'll add a way to pass them via &lt;code&gt;STDIN&lt;/code&gt;.&lt;/p&gt;


&lt;p&gt;Also, what if I want to send them to another vim server ? We'll add this ability too.&lt;/p&gt;


&lt;p&gt;Here is the resulting script:&lt;/p&gt;

&lt;pre&gt;
#!/usr/bin/env bash

# set a default SERVERNAME
SERVERNAME=&amp;quot;ash0&amp;quot;

# look for files on stdin
if ! [ -t 0 ]; then
  FILES=`cat /dev/stdin`
else
  exit;
fi;

# now let's check if we want a specific vim server
if ! [ -z $1 ]; then
  SERVERNAME=$1
fi;

# we can now open the files
/usr/bin/gvim --servername $SERVERNAME --remote-silent-tab $FILES
&lt;/pre&gt;


&lt;p&gt;Tada !&lt;/p&gt;


&lt;p&gt;You can now do the followings:&lt;/p&gt;

&lt;pre&gt;
grep foo | sendtovim
grep foo | sendtovim grep0
&lt;/pre&gt;</description>
    
    
    
          <comments>http://mirmodynamics.com/post/2008/10/16/Mass-vim-file-opening-reloaded#comment-form</comments>
      <wfw:comment>http://mirmodynamics.com/post/2008/10/16/Mass-vim-file-opening-reloaded#comment-form</wfw:comment>
      <wfw:commentRss>http://mirmodynamics.com/feed/atom/comments/1144</wfw:commentRss>
      </item>
    
  <item>
    <title>A specific stylesheet for each module</title>
    <link>http://mirmodynamics.com/post/2008/10/15/A-specific-stylesheet-for-each-module</link>
    <guid isPermaLink="false">urn:md5:3d62ec1a3d453aff01166ab7a3582263</guid>
    <pubDate>Wed, 15 Oct 2008 00:43:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Symfony</category>
        <category>configuration</category><category>css</category><category>stylesheets</category><category>symfony</category><category>tips</category><category>yaml</category>    
    <description>    &lt;p&gt;So this is the first post of the newly opened &lt;a href=&quot;http://mirmodynamics.com/category/symfony&quot;&gt;symfony category&lt;/a&gt; of this blog, and I want to make things clear right now: you (most likely) won't find (yet) any &lt;strong&gt;pro&lt;/strong&gt;tip or high level symfony tutorials here, as I'm still in the process of learning symfony. The good news though is that I'm currently assigned an 1.2-DEV project, so you may get some insight at what's up in the dev branch of the framework (especially regarding sfForm) :-)&lt;/p&gt;


&lt;p&gt;If your are looking for more complete material on the subject, please redirect yourself to &lt;a href=&quot;http://www.symfony-project.org/&quot;&gt;the official website&lt;/a&gt; (where you can find the documentation and a very interesting blog) or &lt;a href=&quot;http://www.aide-de-camp.org/&quot;&gt;Fabien's blog&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;That said, I think it could be interesting to post all the little things I learn everyday that make development with symfony easier for the everyday php developper that you might be if you made it this far into this post ;-)&lt;/p&gt;


&lt;p&gt;Soooo, let's begin the show, with some yaml magic. Yaml I said ? Yaml I said. For those not knowing yet, yaml is the format of choice for symfony's configurations file. So what's the point between configuration files and stylesheets ? Let's say you've got a symfony application (say, frontend), and you'd like a particular module (say, news) in this application to have its own stylesheet in addition of the defaults stylesheets you defined already. Very simple, you start by creating the adequate configuration file:&lt;/p&gt;

&lt;pre&gt;
cd apps/frontend/modules/news/
mkdir config
vi config/view.yml
&lt;/pre&gt;


&lt;p&gt;All you have to do know is declare the stylesheet:&lt;/p&gt;

&lt;pre&gt;
all:
  stylesheets: [news]
&lt;/pre&gt;


&lt;p&gt;And that's all, no helper call in the layout, your &lt;code&gt;news.css&lt;/code&gt; will automagically be appended to the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; of your generated html. You can also declare multiples css, or control which actions get a particular css, and even specify to which media they apply:&lt;/p&gt;

&lt;pre&gt;
all:
  stylesheets: [news, news_print: { media: print }]
list:
  stylesheets: [list]
&lt;/pre&gt;


&lt;p&gt;Handy, heh.&lt;/p&gt;


&lt;p&gt;But that's not all ! If you're not that much into yaml, you can use a view helper, directly into your template:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;?php use_stylesheet('news'); ?&amp;gt;
&lt;/pre&gt;


&lt;p&gt;Or even add it from the controller:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;?php $this-&amp;gt;getResponse()-&amp;gt;addStylesheet('news'); ?&amp;gt;
&lt;/pre&gt;</description>
    
    
    
          <comments>http://mirmodynamics.com/post/2008/10/15/A-specific-stylesheet-for-each-module#comment-form</comments>
      <wfw:comment>http://mirmodynamics.com/post/2008/10/15/A-specific-stylesheet-for-each-module#comment-form</wfw:comment>
      <wfw:commentRss>http://mirmodynamics.com/feed/atom/comments/1142</wfw:commentRss>
      </item>
    
  <item>
    <title>Mass vim file opening</title>
    <link>http://mirmodynamics.com/post/2008/10/14/Mass-vim-file-opening</link>
    <guid isPermaLink="false">urn:md5:d2b7afaa2aaf18ada08b02c96c5185fc</guid>
    <pubDate>Tue, 14 Oct 2008 19:40:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Geekeries</category>
        <category>grep</category><category>handy</category><category>script</category><category>tips</category><category>vim</category>    
    <description>    &lt;p&gt;Remember &lt;a href=&quot;http://mirmodynamics.com/post/2006/11/28/Linux-gVim-Rox-filer-Mon-IDE&quot;&gt;my old post about vim and rox-filer&lt;/a&gt; ? Well I've got one tiny and silly addition to it now, I can mass open files from any shell command line, with this little script placed in my &lt;code&gt;~/bin/&lt;/code&gt; (don't forget to &lt;code&gt;chmod +x&lt;/code&gt;):&lt;/p&gt;

&lt;pre&gt;
for i in $*; do
  /usr/bin/gvim --servername ash0 --remote-silent-tab $i
  sleep 1
done;
&lt;/pre&gt;


&lt;p&gt;The &lt;code&gt;sleep 1&lt;/code&gt; is necessary as vim does not seem to like being flooded with files.&lt;/p&gt;


&lt;p&gt;Example usage:&lt;/p&gt;

&lt;pre&gt;
sendtovim `grep foo *`
&lt;/pre&gt;


&lt;p&gt;Opens in vim all files containing &amp;quot;foo&amp;quot; in the current directory. Who said handy ?&lt;/p&gt;


&lt;p&gt;Note: I know have an &lt;a href=&quot;http://mirmodynamics.com/post/2008/10/16/Mass-vim-file-opening-reloaded&quot;&gt;updated and useful version of this script&lt;/a&gt;&lt;/p&gt;</description>
    
    
    
          <comments>http://mirmodynamics.com/post/2008/10/14/Mass-vim-file-opening#comment-form</comments>
      <wfw:comment>http://mirmodynamics.com/post/2008/10/14/Mass-vim-file-opening#comment-form</wfw:comment>
      <wfw:commentRss>http://mirmodynamics.com/feed/atom/comments/1141</wfw:commentRss>
      </item>
    
  <item>
    <title>Quick php5 pre-migration check</title>
    <link>http://mirmodynamics.com/post/2007/08/30/Quick-php5-pre-migration-check</link>
    <guid isPermaLink="false">urn:md5:2e44d92a67a44664619078b9766c1b5f</guid>
    <pubDate>Thu, 30 Aug 2007 11:57:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Geekeries</category>
        <category>migration</category><category>php</category><category>php5</category><category>quick</category><category>syntax check</category><category>tips</category>    
    <description>    &lt;p&gt;If you're wondering how much of a hassle it would be to migrate your app / codebase to php5, try the following command line (after having installed the php5-cli package of course):&lt;/p&gt;


&lt;pre&gt;find . -name &amp;quot;*.php&amp;quot; -exec /usr/bin/php5 -l {} \; | grep -v 'No syntax errors'&lt;/pre&gt;


&lt;p&gt;It'll show you all the files with syntax errors in it.&lt;/p&gt;</description>
    
    
    
          <comments>http://mirmodynamics.com/post/2007/08/30/Quick-php5-pre-migration-check#comment-form</comments>
      <wfw:comment>http://mirmodynamics.com/post/2007/08/30/Quick-php5-pre-migration-check#comment-form</wfw:comment>
      <wfw:commentRss>http://mirmodynamics.com/feed/atom/comments/1006</wfw:commentRss>
      </item>
    
  <item>
    <title>Get the current $view from a view helper</title>
    <link>http://mirmodynamics.com/post/2007/07/01/Get-the-current-view-from-a-view-helper</link>
    <guid isPermaLink="false">urn:md5:6ea0301d94edd4aa84034fb7e5596e87</guid>
    <pubDate>Sun, 01 Jul 2007 22:24:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>php</category><category>tips</category><category>view</category><category>view helper</category><category>zend framework</category>    
    <description>    &lt;p&gt;So you're making your own view helper and you need, for a reason, to access the running &lt;code&gt;$view&lt;/code&gt; instance. Don't worry, all you have to do is implement a &lt;code&gt;setView()&lt;/code&gt; method which will be called on your helper's instantiation, with the &lt;code&gt;$view&lt;/code&gt; as argument:&lt;/p&gt;

&lt;pre&gt;
class My_View_Helper_SpecialPurpose {
	
	protected $_view = null;
	
	public function setView($view) {
		$this-&amp;gt;_view = $view;
	}

}
&lt;/pre&gt;


&lt;p&gt;And voila !&lt;/p&gt;</description>
    
    
    
          <comments>http://mirmodynamics.com/post/2007/07/01/Get-the-current-view-from-a-view-helper#comment-form</comments>
      <wfw:comment>http://mirmodynamics.com/post/2007/07/01/Get-the-current-view-from-a-view-helper#comment-form</wfw:comment>
      <wfw:commentRss>http://mirmodynamics.com/feed/atom/comments/873</wfw:commentRss>
      </item>
    
</channel>
</rss>