<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog.hio.fr &#187; php</title>
	<atom:link href="http://blog.hio.fr/category/dev/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.hio.fr</link>
	<description></description>
	<lastBuildDate>Wed, 30 Jun 2010 09:16:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>PHP, Comment calculer N jours depuis une date</title>
		<link>http://blog.hio.fr/2010/06/08/php-comment-calculer-n-jours-depuis-une-date/</link>
		<comments>http://blog.hio.fr/2010/06/08/php-comment-calculer-n-jours-depuis-une-date/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 18:57:37 +0000</pubDate>
		<dc:creator>HiO</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.hio.fr/?p=562</guid>
		<description><![CDATA[J'ai eu besoin de calculer 92 jour depuis le jour J+1, donc voila, le petit algo mignon.]]></description>
			<content:encoded><![CDATA[<p>J&#8217;ai eu besoin de calculer 92 jour depuis le jour J+1, donc voila, le petit algo mignon.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #000088;">$month</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$year</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$day</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d'</span><span style="color: #339933;">,</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$month</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d'</span><span style="color: #339933;">,</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;+1 day&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$year</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'t'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #000088;">$month</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m'</span><span style="color: #339933;">,</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'+1 month'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$dateArray</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$dateArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>  
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$j</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$day</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">92</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++,</span><span style="color: #000088;">$j</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$tmp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$j</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'t'</span><span style="color: #339933;">,</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$month</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'01'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$year</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$j</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$month</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$year</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y'</span><span style="color: #339933;">,</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'01'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'01'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$year</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$month</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m'</span><span style="color: #339933;">,</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$month</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'01'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$year</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$j</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'0'</span><span style="color: #339933;">.</span><span style="color: #000088;">$j</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">else</span>
        <span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$j</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$month</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'0'</span><span style="color: #339933;">.</span><span style="color: #000088;">$month</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">else</span>
        <span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$month</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$year</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$dateArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tmp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>ce qui donne une fois passer a un widget symfony qui va bien</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'date_demarage'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormSelect<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'label'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Date de démarrage'</span><span style="color: #339933;">,</span>
                                                                    <span style="color: #0000ff;">'choices'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array_combine</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dateArray</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dateArray</span><span style="color: #009900;">&#41;</span>
                                                                    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;select name=&quot;ventes[date_demarage]&quot; id=&quot;ventes_date_demarage&quot;&gt;
&lt;option value=&quot;&quot; selected=&quot;selected&quot;&gt;&lt;/option&gt;
&lt;option value=&quot;09-06-2010&quot;&gt;09-06-2010&lt;/option&gt;
&lt;option value=&quot;10-06-2010&quot;&gt;10-06-2010&lt;/option&gt;
&lt;option value=&quot;11-06-2010&quot;&gt;11-06-2010&lt;/option&gt;
&lt;option value=&quot;12-06-2010&quot;&gt;12-06-2010&lt;/option&gt;
&lt;option value=&quot;13-06-2010&quot;&gt;13-06-2010&lt;/option&gt;
&lt;option value=&quot;14-06-2010&quot;&gt;14-06-2010&lt;/option&gt;
&lt;option value=&quot;15-06-2010&quot;&gt;15-06-2010&lt;/option&gt;
&lt;option value=&quot;16-06-2010&quot;&gt;16-06-2010&lt;/option&gt;
&lt;option value=&quot;17-06-2010&quot;&gt;17-06-2010&lt;/option&gt;
&lt;option value=&quot;18-06-2010&quot;&gt;18-06-2010&lt;/option&gt;
&lt;option value=&quot;19-06-2010&quot;&gt;19-06-2010&lt;/option&gt;
&lt;option value=&quot;20-06-2010&quot;&gt;20-06-2010&lt;/option&gt;
&lt;option value=&quot;21-06-2010&quot;&gt;21-06-2010&lt;/option&gt;
&lt;option value=&quot;22-06-2010&quot;&gt;22-06-2010&lt;/option&gt;
&lt;option value=&quot;23-06-2010&quot;&gt;23-06-2010&lt;/option&gt;
&lt;option value=&quot;24-06-2010&quot;&gt;24-06-2010&lt;/option&gt;
&lt;option value=&quot;25-06-2010&quot;&gt;25-06-2010&lt;/option&gt;
&lt;option value=&quot;26-06-2010&quot;&gt;26-06-2010&lt;/option&gt;
&lt;option value=&quot;27-06-2010&quot;&gt;27-06-2010&lt;/option&gt;
&lt;option value=&quot;28-06-2010&quot;&gt;28-06-2010&lt;/option&gt;
&lt;option value=&quot;29-06-2010&quot;&gt;29-06-2010&lt;/option&gt;
&lt;option value=&quot;30-06-2010&quot;&gt;30-06-2010&lt;/option&gt;
&lt;option value=&quot;01-07-2010&quot;&gt;01-07-2010&lt;/option&gt;
&lt;option value=&quot;02-07-2010&quot;&gt;02-07-2010&lt;/option&gt;
&lt;option value=&quot;03-07-2010&quot;&gt;03-07-2010&lt;/option&gt;
&lt;option value=&quot;04-07-2010&quot;&gt;04-07-2010&lt;/option&gt;
&lt;option value=&quot;05-07-2010&quot;&gt;05-07-2010&lt;/option&gt;
&lt;option value=&quot;06-07-2010&quot;&gt;06-07-2010&lt;/option&gt;
&lt;option value=&quot;07-07-2010&quot;&gt;07-07-2010&lt;/option&gt;
&lt;option value=&quot;08-07-2010&quot;&gt;08-07-2010&lt;/option&gt;
&lt;option value=&quot;09-07-2010&quot;&gt;09-07-2010&lt;/option&gt;
&lt;option value=&quot;10-07-2010&quot;&gt;10-07-2010&lt;/option&gt;
&lt;option value=&quot;11-07-2010&quot;&gt;11-07-2010&lt;/option&gt;
&lt;option value=&quot;12-07-2010&quot;&gt;12-07-2010&lt;/option&gt;
&lt;option value=&quot;13-07-2010&quot;&gt;13-07-2010&lt;/option&gt;
&lt;option value=&quot;14-07-2010&quot;&gt;14-07-2010&lt;/option&gt;
&lt;option value=&quot;15-07-2010&quot;&gt;15-07-2010&lt;/option&gt;
&lt;option value=&quot;16-07-2010&quot;&gt;16-07-2010&lt;/option&gt;
&lt;option value=&quot;17-07-2010&quot;&gt;17-07-2010&lt;/option&gt;
&lt;option value=&quot;18-07-2010&quot;&gt;18-07-2010&lt;/option&gt;
&lt;option value=&quot;19-07-2010&quot;&gt;19-07-2010&lt;/option&gt;
&lt;option value=&quot;20-07-2010&quot;&gt;20-07-2010&lt;/option&gt;
&lt;option value=&quot;21-07-2010&quot;&gt;21-07-2010&lt;/option&gt;
&lt;option value=&quot;22-07-2010&quot;&gt;22-07-2010&lt;/option&gt;
&lt;option value=&quot;23-07-2010&quot;&gt;23-07-2010&lt;/option&gt;
&lt;option value=&quot;24-07-2010&quot;&gt;24-07-2010&lt;/option&gt;
&lt;option value=&quot;25-07-2010&quot;&gt;25-07-2010&lt;/option&gt;
&lt;option value=&quot;26-07-2010&quot;&gt;26-07-2010&lt;/option&gt;
&lt;option value=&quot;27-07-2010&quot;&gt;27-07-2010&lt;/option&gt;
&lt;option value=&quot;28-07-2010&quot;&gt;28-07-2010&lt;/option&gt;
&lt;option value=&quot;29-07-2010&quot;&gt;29-07-2010&lt;/option&gt;
&lt;option value=&quot;30-07-2010&quot;&gt;30-07-2010&lt;/option&gt;
&lt;option value=&quot;31-07-2010&quot;&gt;31-07-2010&lt;/option&gt;
&lt;option value=&quot;01-08-2010&quot;&gt;01-08-2010&lt;/option&gt;
&lt;option value=&quot;02-08-2010&quot;&gt;02-08-2010&lt;/option&gt;
&lt;option value=&quot;03-08-2010&quot;&gt;03-08-2010&lt;/option&gt;
&lt;option value=&quot;04-08-2010&quot;&gt;04-08-2010&lt;/option&gt;
&lt;option value=&quot;05-08-2010&quot;&gt;05-08-2010&lt;/option&gt;
&lt;option value=&quot;06-08-2010&quot;&gt;06-08-2010&lt;/option&gt;
&lt;option value=&quot;07-08-2010&quot;&gt;07-08-2010&lt;/option&gt;
&lt;option value=&quot;08-08-2010&quot;&gt;08-08-2010&lt;/option&gt;
&lt;option value=&quot;09-08-2010&quot;&gt;09-08-2010&lt;/option&gt;
&lt;option value=&quot;10-08-2010&quot;&gt;10-08-2010&lt;/option&gt;
&lt;option value=&quot;11-08-2010&quot;&gt;11-08-2010&lt;/option&gt;
&lt;option value=&quot;12-08-2010&quot;&gt;12-08-2010&lt;/option&gt;
&lt;option value=&quot;13-08-2010&quot;&gt;13-08-2010&lt;/option&gt;
&lt;option value=&quot;14-08-2010&quot;&gt;14-08-2010&lt;/option&gt;
&lt;option value=&quot;15-08-2010&quot;&gt;15-08-2010&lt;/option&gt;
&lt;option value=&quot;16-08-2010&quot;&gt;16-08-2010&lt;/option&gt;
&lt;option value=&quot;17-08-2010&quot;&gt;17-08-2010&lt;/option&gt;
&lt;option value=&quot;18-08-2010&quot;&gt;18-08-2010&lt;/option&gt;
&lt;option value=&quot;19-08-2010&quot;&gt;19-08-2010&lt;/option&gt;
&lt;option value=&quot;20-08-2010&quot;&gt;20-08-2010&lt;/option&gt;
&lt;option value=&quot;21-08-2010&quot;&gt;21-08-2010&lt;/option&gt;
&lt;option value=&quot;22-08-2010&quot;&gt;22-08-2010&lt;/option&gt;
&lt;option value=&quot;23-08-2010&quot;&gt;23-08-2010&lt;/option&gt;
&lt;option value=&quot;24-08-2010&quot;&gt;24-08-2010&lt;/option&gt;
&lt;option value=&quot;25-08-2010&quot;&gt;25-08-2010&lt;/option&gt;
&lt;option value=&quot;26-08-2010&quot;&gt;26-08-2010&lt;/option&gt;
&lt;option value=&quot;27-08-2010&quot;&gt;27-08-2010&lt;/option&gt;
&lt;option value=&quot;28-08-2010&quot;&gt;28-08-2010&lt;/option&gt;
&lt;option value=&quot;29-08-2010&quot;&gt;29-08-2010&lt;/option&gt;
&lt;option value=&quot;30-08-2010&quot;&gt;30-08-2010&lt;/option&gt;
&lt;option value=&quot;31-08-2010&quot;&gt;31-08-2010&lt;/option&gt;
&lt;option value=&quot;01-09-2010&quot;&gt;01-09-2010&lt;/option&gt;
&lt;option value=&quot;02-09-2010&quot;&gt;02-09-2010&lt;/option&gt;
&lt;option value=&quot;03-09-2010&quot;&gt;03-09-2010&lt;/option&gt;
&lt;option value=&quot;04-09-2010&quot;&gt;04-09-2010&lt;/option&gt;
&lt;option value=&quot;05-09-2010&quot;&gt;05-09-2010&lt;/option&gt;
&lt;option value=&quot;06-09-2010&quot;&gt;06-09-2010&lt;/option&gt;
&lt;option value=&quot;07-09-2010&quot;&gt;07-09-2010&lt;/option&gt;
&lt;option value=&quot;08-09-2010&quot;&gt;08-09-2010&lt;/option&gt;
&lt;/select&gt;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.hio.fr/2010/06/08/php-comment-calculer-n-jours-depuis-une-date/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Symfony, Comment définir un groupe avec sfGuardDoctrinePlugin lors d&#8217;une inscription</title>
		<link>http://blog.hio.fr/2010/06/03/php-symfony-comment-definir-un-groupe-avec-sfguarddoctrineplugin-lors-dune-inscription/</link>
		<comments>http://blog.hio.fr/2010/06/03/php-symfony-comment-definir-un-groupe-avec-sfguarddoctrineplugin-lors-dune-inscription/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 20:08:02 +0000</pubDate>
		<dc:creator>HiO</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://blog.hio.fr/?p=560</guid>
		<description><![CDATA[Tout est dans le titre
<pre lang="php">
protected function processForm(sfWebRequest $request, sfForm $form)
{
  $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
  if($form->isValid())
  {
    $register = $form->save();
    $register->addGroupByName('member');
    $register->addPermissionByName('member');
    $register->profile->setSfGuardUserId($register->id);
    $register->save();
    $this->getUser()->signIn($this->form->getObject());
    $this->redirect('@feeds');
  }
  $this->getUser()->setFlash('error','formular is not correctly filled.');
}
</pre>]]></description>
			<content:encoded><![CDATA[<p>Tout est dans le titre</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">protected <span style="color: #000000; font-weight: bold;">function</span> processForm<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</span><span style="color: #339933;">,</span> sfForm <span style="color: #000088;">$form</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFiles</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isValid</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$register</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$register</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addGroupByName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'member'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$register</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addPermissionByName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'member'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$register</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">profile</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setSfGuardUserId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$register</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$register</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">signIn</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'@feeds'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFlash</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'formular is not correctly filled.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.hio.fr/2010/06/03/php-symfony-comment-definir-un-groupe-avec-sfguarddoctrineplugin-lors-dune-inscription/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Symfony, exemple d&#8217;utilisation de widget et validateur</title>
		<link>http://blog.hio.fr/2010/04/16/php-symfony-exemple-dutilisation-de-widget-et-validateur/</link>
		<comments>http://blog.hio.fr/2010/04/16/php-symfony-exemple-dutilisation-de-widget-et-validateur/#comments</comments>
		<pubDate>Fri, 16 Apr 2010 12:53:59 +0000</pubDate>
		<dc:creator>HiO</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[validator]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://blog.hio.fr/?p=540</guid>
		<description><![CDATA[Voici des exemples d'utilisation des widgets et des validateurs symfony, liste mise a jour au fur et a mesure de mes besoins ^^]]></description>
			<content:encoded><![CDATA[<p>Voici des exemples d&#8217;utilisation des widgets et des validateurs symfony, liste mise a jour au fur et a mesure de mes besoins ^^</p>
<h2>Widgets</h2>
<p><strong>sfWidgetFormDoctrineChoice</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cat_id'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormDoctrineChoice<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'label'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Category'</span><span style="color: #339933;">,</span>
                                                                      <span style="color: #0000ff;">'model'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'hosts_categories'</span><span style="color: #339933;">,</span>
                                                                      <span style="color: #0000ff;">'add_empty'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>sfWidgetFormInputPassword</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormInputPassword<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Validateurs</h2>
<p><strong>sfValidatorRegex</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'intervalle'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorRegex<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pattern'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'/^[0-9]{1}[i,m,d]{1}$/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>sfValidatorOr</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'intervalle'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorOr<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> sfValidatorRegex<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pattern'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'/^[0-9]{1}[i,m,d]{1}$/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                                                                <span style="color: #000000; font-weight: bold;">new</span> sfValidatorRegex<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pattern'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'/^[0-9]{1}[i,m,d]{1};[0-9]{2}h[0-9]{2}$/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>sfValidatorAnd</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validatorSchema</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setPostValidator</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> sfValidatorAnd<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> sfValidatorSchemaCompare<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'repassword'</span><span style="color: #339933;">,</span>  sfValidatorSchemaCompare<span style="color: #339933;">::</span><span style="color: #004000;">EQUAL</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                                                                  <span style="color: #000000; font-weight: bold;">new</span> sfValidatorDoctrineUnique<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'model'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'sfGuardUser'</span><span style="color: #339933;">,</span>
                                                                                                      <span style="color: #0000ff;">'column'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'invalid'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'This username already taken.'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                                                                  <span style="color: #000000; font-weight: bold;">new</span> sfValidatorDoctrineUnique<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'model'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'sfGuardUser'</span><span style="color: #339933;">,</span>
                                                                                                      <span style="color: #0000ff;">'column'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'email_address'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'invalid'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'This email address already taken.'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                                                                  <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>sfValidatorSchemaCompare</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorString<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'min_length'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'max_length'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'repassword'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorString<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validatorSchema</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setPostValidator</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> sfValidatorSchemaCompare<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'repassword'</span><span style="color: #339933;">,</span>  sfValidatorSchemaCompare<span style="color: #339933;">::</span><span style="color: #004000;">EQUAL</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.hio.fr/2010/04/16/php-symfony-exemple-dutilisation-de-widget-et-validateur/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Symfony, Comment passer une valeur a un objet sfForm dans le backend d&#8217;une application</title>
		<link>http://blog.hio.fr/2010/04/12/php-symfony-comment-passer-une-valeur-a-un-objet-sfform-dans-le-backend-dune-application/</link>
		<comments>http://blog.hio.fr/2010/04/12/php-symfony-comment-passer-une-valeur-a-un-objet-sfform-dans-le-backend-dune-application/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 13:00:36 +0000</pubDate>
		<dc:creator>HiO</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://blog.hio.fr/?p=535</guid>
		<description><![CDATA[<strong>apps/backend/modules/hosts/actions/actions.class.php</strong>
<pre lang="php" line="1">
class hostsActions extends autoHostsActions
{

  public function executeCreate(sfWebRequest $request)
  {
    $this->form = $this->configuration->getForm();
    $this->hosts = $this->form->getObject();
                                                                                                                                            
    $tainted_values = $request->getParameter($this->form->getName());     
    $tainted_values['user_id'] = $this->getUser()->getGuardUser()->getId();

    $request->setParameter($this->form->getName(), $tainted_values);
    parent::processForm($request, $this->form);
    $this->setTemplate('new');
  }
}
</pre>]]></description>
			<content:encoded><![CDATA[<p><strong>apps/backend/modules/hosts/actions/actions.class.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> hostsActions <span style="color: #000000; font-weight: bold;">extends</span> autoHostsActions
<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeCreate<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">configuration</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getForm</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hosts</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$tainted_values</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     
    <span style="color: #000088;">$tainted_values</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user_id'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getGuardUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setParameter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tainted_values</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    parent<span style="color: #339933;">::</span><span style="color: #004000;">processForm</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTemplate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'new'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.hio.fr/2010/04/12/php-symfony-comment-passer-une-valeur-a-un-objet-sfform-dans-le-backend-dune-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Symfony, Comment récupérer la route courante dans les templates</title>
		<link>http://blog.hio.fr/2010/03/26/comment-recuperer-la-route-courante-dans-les-templates/</link>
		<comments>http://blog.hio.fr/2010/03/26/comment-recuperer-la-route-courante-dans-les-templates/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 14:32:42 +0000</pubDate>
		<dc:creator>HiO</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://blog.hio.fr/?p=531</guid>
		<description><![CDATA[<strong>indexSuccess.php</strong>
<pre lang="php">
sfContext::getInstance()->getRouting()->getCurrentRouteName()
</pre>

Renvoi
"homepage"
Si votre route s'appelle "homepage" bien sur ^^
<pre lang="yaml">
homepage:
  url: /
  param: { module: product, action: index }
</pre>]]></description>
			<content:encoded><![CDATA[<p><strong>indexSuccess.php</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">sfContext<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRouting</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCurrentRouteName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>Renvoi<br />
&laquo;&nbsp;homepage&nbsp;&raquo;<br />
Si votre route s&#8217;appelle &laquo;&nbsp;homepage&nbsp;&raquo; bien sur ^^</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">homepage:
  url: /
  param: { module: product, action: index }</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.hio.fr/2010/03/26/comment-recuperer-la-route-courante-dans-les-templates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP session avec memcached</title>
		<link>http://blog.hio.fr/2010/01/16/php-session-avec-memcached/</link>
		<comments>http://blog.hio.fr/2010/01/16/php-session-avec-memcached/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 15:58:24 +0000</pubDate>
		<dc:creator>HiO</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://blog.hio.fr/?p=509</guid>
		<description><![CDATA[Comment stocker les session php dans un memcached en 1 minute chrono 

GO !]]></description>
			<content:encoded><![CDATA[<p>Comment stocker les session php dans un memcached en 1 minute chrono </p>
<p>GO !</p>
<p><strong>Installation de memcached</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> memcached
<span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-memcache</pre></div></div>

<p>modifier la conf dans /etc/memcached.conf au besoin (augmenter la memoire utiliser, etc&#8230;)</p>
<p>et ensuite dans le php.ini qui devrai se trouver ici /etc/php5/apache2/php.ini</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">session.save_handler <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> memcache</span>
session.save_path<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;tcp://127.0.0.1:11211?persistent=1&amp;weight=1&amp;timeout=1&amp;retry_interval=15&quot;</span></pre></div></div>

<p><strong>On restart apache</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apache2 restart</pre></div></div>

<p>un petit script php pour voir se qu&#8217;il se passe<br />
<a href="http://livebookmark.net/journal/2008/05/21/memcachephp-stats-like-apcphp/"> http://livebookmark.net/journal/2008/05/21/memcachephp-stats-like-apcphp/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hio.fr/2010/01/16/php-session-avec-memcached/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Symfony, Comment changer les messages par defaut des validateurs Symfony</title>
		<link>http://blog.hio.fr/2010/01/14/comment-changer-les-messages-par-defaut-des-validateurs-symfony/</link>
		<comments>http://blog.hio.fr/2010/01/14/comment-changer-les-messages-par-defaut-des-validateurs-symfony/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 14:23:51 +0000</pubDate>
		<dc:creator>HiO</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://blog.hio.fr/?p=389</guid>
		<description><![CDATA[Comment faire , quand on veut changer tous les messages par défaut des validateurs Symfony , sans les définir un par un par un bete 'message' => 'mais blublu' et sans allez les changer directement dans les entrailles de symfony ce qui est mal !!! C'est mal !!!]]></description>
			<content:encoded><![CDATA[<p>Comment faire , quand on veut changer tous les messages par défaut des validateurs Symfony , sans les définir un par un par un bete &#8216;message&#8217; => &#8216;mais blublu&#8217; et sans allez les changer directement dans les entrailles de symfony ce qui est mal !!! C&#8217;est mal !!!</p>
<p>oh oui dit nous père castor<br />
Et bien comme ça</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">    sfValidatorBase<span style="color: #339933;">::</span><span style="color: #004000;">setInvalidMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Champ invalide'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    sfValidatorBase<span style="color: #339933;">::</span><span style="color: #004000;">setRequiredMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Champ obligatoire'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    parent<span style="color: #339933;">::</span><span style="color: #004000;">setup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Ce qui nous donne dans un vrai bout de php</p>
<p><strong>VentesForm.class.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> VentesForm <span style="color: #000000; font-weight: bold;">extends</span> BaseVentesForm
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> configure<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    sfValidatorBase<span style="color: #339933;">::</span><span style="color: #004000;">setInvalidMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Champ invalide'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    sfValidatorBase<span style="color: #339933;">::</span><span style="color: #004000;">setRequiredMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Champ obligatoire'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    parent<span style="color: #339933;">::</span><span style="color: #004000;">setup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'created_at'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'updated_at'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
          <span style="color: #000088;">$this</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'expires_at'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'is_active'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uid'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormInput<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'hidden'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'is_hidden'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'civ'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormChoice<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'choices'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'M.'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'M.'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Mme'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Mme'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Mlle'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Mlle'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'adresse1'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormTextarea<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'adresse2'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormTextarea<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'adresse3'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormTextarea<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorEmail<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'invalid'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'L\'adresse email saisie est incorrecte'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLabel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'numeroabo'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'N°Abonné'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><a href="http://www.symfony-project.org/api/1_2/sfValidatorBase">sfValidatorBase</a></p>
<p><strong>NOTE:</strong><br />
Deprecated depuis la version 1.4 de symfony remplacer par<br />
sfValidatorBase::setDefaultMessage() method</p>
<p><a href="http://www.symfony-project.org/tutorial/1_4/en/deprecated">http://www.symfony-project.org/tutorial/1_4/en/deprecated</a></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">sfValidatorBase<span style="color: #339933;">::</span><span style="color: #004000;">setDefaultMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'invalid'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Champ invalide'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
sfValidatorBase<span style="color: #339933;">::</span><span style="color: #004000;">setDefaultMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'required'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Champ obligatoire'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
parent<span style="color: #339933;">::</span><span style="color: #004000;">setup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.hio.fr/2010/01/14/comment-changer-les-messages-par-defaut-des-validateurs-symfony/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Symfony Text Helper</title>
		<link>http://blog.hio.fr/2010/01/08/php-symfony-text-helper/</link>
		<comments>http://blog.hio.fr/2010/01/08/php-symfony-text-helper/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 08:14:01 +0000</pubDate>
		<dc:creator>HiO</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[helper]]></category>

		<guid isPermaLink="false">http://blog.hio.fr/?p=490</guid>
		<description><![CDATA[Text Helper]]></description>
			<content:encoded><![CDATA[<p><strong>Text Helper</strong><br />
<a href="http://www.symfony-project.org/api/1_4/TextHelper">http://www.symfony-project.org/api/1_4/TextHelper</a></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">echo</span> use_helper<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Text'</span><span style="color: #009900;">&#41;</span>
<span style="color: #b1b100;">echo</span> auto_link_text<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Turns all urls and email addresses into clickable links. The +link+ parameter can limit what should be linked.</span>
<span style="color: #b1b100;">echo</span> excerpt_text<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Extracts an excerpt from the +text+ surrounding the +phrase+ with a number of characters on each side determined</span>
<span style="color: #b1b100;">echo</span> highlight_text<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$phrase</span><span style="color: #339933;">,</span> <span style="color: #000088;">$highlighter</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Highlights the +phrase+ where it is found in the +text+ by surrounding it like</span>
<span style="color: #b1b100;">echo</span> simple_format_text<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>  <span style="color: #666666; font-style: italic;">// Returns +text+ transformed into html using very simple formatting rules</span>
<span style="color: #b1b100;">echo</span> strip_links_text<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Turns all links into words, like &quot;&lt;a href=&quot;something&quot;&gt;else&lt;/a&gt;&quot; to &quot;else&quot;.</span>
<span style="color: #b1b100;">echo</span> truncate_text<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Truncates +text+ to the length of +length+ and replaces the last three characters with the +truncate_string+</span>
<span style="color: #b1b100;">echo</span> wrap_text<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Word wrap long lines to line_width.</span>
<span style="color: #b1b100;">echo</span> _auto_link_email_addresses<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Turns all email addresses into clickable links.</span>
<span style="color: #b1b100;">echo</span> _auto_link_urls<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Turns all urls into clickable links</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.hio.fr/2010/01/08/php-symfony-text-helper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Symfony Date Helper</title>
		<link>http://blog.hio.fr/2009/12/24/php-symfony-divers/</link>
		<comments>http://blog.hio.fr/2009/12/24/php-symfony-divers/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 15:52:45 +0000</pubDate>
		<dc:creator>HiO</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[helper]]></category>

		<guid isPermaLink="false">http://blog.hio.fr/?p=484</guid>
		<description><![CDATA[Date helper]]></description>
			<content:encoded><![CDATA[<p><strong>Date helper</strong><br />
<a href="http://www.symfony-project.org/api/1_4/DateHelper">http://www.symfony-project.org/api/1_4/DateHelper</a></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
use_helper<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Date'</span><span style="color: #009900;">&#41;</span> 
<span style="color: #b1b100;">echo</span> format_date<span style="color: #009900;">&#40;</span><span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</span> 
<span style="color: #b1b100;">echo</span> format_date<span style="color: #009900;">&#40;</span><span style="color: #000088;">$date</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'d'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'en'</span><span style="color: #009900;">&#41;</span> 
<span style="color: #b1b100;">echo</span> format_datetime<span style="color: #009900;">&#40;</span><span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</span>
<span style="color: #b1b100;">echo</span> format_date<span style="color: #009900;">&#40;</span><span style="color: #000088;">$date</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'MM/yyyy'</span><span style="color: #009900;">&#41;</span> 
<span style="color: #b1b100;">echo</span> format_daterange<span style="color: #009900;">&#40;</span><span style="color: #000088;">$start_date</span><span style="color: #339933;">,</span> <span style="color: #000088;">$end_date</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'MM/yy'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'from %s to %s'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'starting from %s'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'until %s'</span><span style="color: #009900;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.hio.fr/2009/12/24/php-symfony-divers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Fork it</title>
		<link>http://blog.hio.fr/2009/11/12/php-fork-it/</link>
		<comments>http://blog.hio.fr/2009/11/12/php-fork-it/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 09:20:15 +0000</pubDate>
		<dc:creator>HiO</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[fork]]></category>

		<guid isPermaLink="false">http://blog.hio.fr/?p=467</guid>
		<description><![CDATA[fork it !!!]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> test<span style="color: #009900;">&#40;</span><span style="color: #000088;">$max</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$max</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> fork <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$children</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$threads</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">timestart</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">threads</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$threads</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> forker<span style="color: #009900;">&#40;</span><span style="color: #000088;">$worker</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$pid</span> <span style="color: #339933;">=</span> pcntl_fork<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pid</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pid</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">' PARENT | launching thread (pid: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$pid</span><span style="color: #339933;">.</span><span style="color: #0000ff;">')'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">children</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pid</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">children</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">threads</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$pid</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">children</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          pcntl_waitpid<span style="color: #009900;">&#40;</span><span style="color: #000088;">$pid</span><span style="color: #339933;">,</span> <span style="color: #000088;">$status</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">' CHILD  | working on '</span><span style="color: #339933;">.</span><span style="color: #000088;">$worker</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'('</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #339933;">.</span><span style="color: #0000ff;">')'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$worker</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">' CHILD  | finish '</span><span style="color: #339933;">.</span><span style="color: #000088;">$worker</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'('</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #339933;">.</span><span style="color: #0000ff;">')'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> waitchildrens<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">children</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$child</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      pcntl_waitpid<span style="color: #009900;">&#40;</span><span style="color: #000088;">$child</span><span style="color: #339933;">,</span> <span style="color: #000088;">$status</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$timeend</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$timeend</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">timestart</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">' TIME   | '</span><span style="color: #339933;">.</span><span style="color: #000088;">$time</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' seconde(s)'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$fork</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> fork<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fork</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">forker</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'11111111'</span><span style="color: #339933;">,</span>
                            <span style="color: #0000ff;">'22222222'</span><span style="color: #339933;">,</span>
                            <span style="color: #0000ff;">'33333333'</span><span style="color: #339933;">,</span>
                            <span style="color: #0000ff;">'44444444'</span><span style="color: #339933;">,</span>
                            <span style="color: #0000ff;">'55555555'</span><span style="color: #339933;">,</span>
                            <span style="color: #0000ff;">'66666666'</span><span style="color: #339933;">,</span>
                            <span style="color: #0000ff;">'77777777'</span><span style="color: #339933;">,</span>
                            <span style="color: #0000ff;">'88888888'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fork</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">waitchildrens</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fork</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.hio.fr/2009/11/12/php-fork-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
