snipt

Ctrl+h for KB shortcuts

PHP

Symfony 1.x : Load helper in controller

1
2
3
4
5
6
<?php

public function executeMyAction(sfWebRequest $request) {
    $this->getContext()->getConfiguration()->loadHelpers(array('Url'));
    $this->getUser()->setFlash('notice', "Well done ! Follow this <a href=".url_for("homepage").">link</a>");
}
https://snipt.net/embed/5270bdbab797dafc8122d8a75dd329b0/
https://snipt.net/raw/5270bdbab797dafc8122d8a75dd329b0/
5270bdbab797dafc8122d8a75dd329b0
php
PHP
6
2016-09-21T16:49:36
True
False
True
Oct 29, 2012 at 04:29 AM
/api/public/snipt/45744/
use-url_for-in-action-load-helper
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="k">public</span> <span class="k">function</span> <span class="nf">executeMyAction</span><span class="p">(</span><span class="nx">sfWebRequest</span> <span class="nv">$request</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">getContext</span><span class="p">()</span><span class="o">-&gt;</span><span class="na">getConfiguration</span><span class="p">()</span><span class="o">-&gt;</span><span class="na">loadHelpers</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">&#39;Url&#39;</span><span class="p">));</span> </span><span id="L-5"><a name="L-5"></a> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">getUser</span><span class="p">()</span><span class="o">-&gt;</span><span class="na">setFlash</span><span class="p">(</span><span class="s1">&#39;notice&#39;</span><span class="p">,</span> <span class="s2">&quot;Well done ! Follow this &lt;a href=&quot;</span><span class="o">.</span><span class="nx">url_for</span><span class="p">(</span><span class="s2">&quot;homepage&quot;</span><span class="p">)</span><span class="o">.</span><span class="s2">&quot;&gt;link&lt;/a&gt;&quot;</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
Helper, Symfony

Text only

Symfony 1.x : Add Error 500 page

1
2
3
4
5
6
7
Add the file error.html.php in /config/error

To test it, add this in your action:
throw new sfException('Testing the 500 error');

To see it don't forget to set your $debug at false in your front controller:
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', false);
https://snipt.net/embed/8c3aa50151a5ace72a2f03c71c332a23/
https://snipt.net/raw/8c3aa50151a5ace72a2f03c71c332a23/
8c3aa50151a5ace72a2f03c71c332a23
text
Text only
7
2016-09-25T03:05:20
True
False
True
Oct 12, 2012 at 09:58 AM
/api/public/snipt/47349/
symfony-1x-error-500-prod
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>Add the file error.html.php in /config/error </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>To test it, add this in your action: </span><span id="L-4"><a name="L-4"></a>throw new sfException(&#39;Testing the 500 error&#39;); </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a>To see it don&#39;t forget to set your $debug at false in your front controller: </span><span id="L-7"><a name="L-7"></a>$configuration = ProjectConfiguration::getApplicationConfiguration(&#39;frontend&#39;, &#39;dev&#39;, false); </span></pre></div> </td></tr></table>
"error 500", Symfony

CSS

Symfony 1.x : Style auto on sfWidgetFormDate rendering

1
2
3
4
5
select[name$="[day]"],
select[name$="[month]"],
select[name$="[year]"] {
    width: 70px;
}
https://snipt.net/embed/adc6c153366a65612fb199a73d545a95/
https://snipt.net/raw/adc6c153366a65612fb199a73d545a95/
adc6c153366a65612fb199a73d545a95
css
CSS
5
2016-09-25T10:03:52
True
False
True
Sep 16, 2012 at 09:49 AM
/api/public/snipt/47249/
symfony-1x-style-auto-on-sfwidgetformdate-rendering
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="nt">select</span><span class="o">[</span><span class="nt">name</span><span class="o">$=</span><span class="s2">&quot;[day]&quot;</span><span class="o">],</span> </span><span id="L-2"><a name="L-2"></a><span class="nt">select</span><span class="o">[</span><span class="nt">name</span><span class="o">$=</span><span class="s2">&quot;[month]&quot;</span><span class="o">],</span> </span><span id="L-3"><a name="L-3"></a><span class="nt">select</span><span class="o">[</span><span class="nt">name</span><span class="o">$=</span><span class="s2">&quot;[year]&quot;</span><span class="o">]</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">width</span><span class="o">:</span> <span class="m">70px</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
Symfony, css, date

PHP

Symfony 1.x : Show last executed query with Propel

1
2
3
<?php 

echo  Propel::getConnection()->getLastExecutedQuery();
https://snipt.net/embed/9135163b3940f8eacccd4f6e199c003b/
https://snipt.net/raw/9135163b3940f8eacccd4f6e199c003b/
9135163b3940f8eacccd4f6e199c003b
php
PHP
3
2016-09-22T03:54:42
True
False
True
Sep 05, 2012 at 04:14 AM
/api/public/snipt/46708/
symfony-1x-show-last-executed-query-with-propel
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="k">echo</span> <span class="nx">Propel</span><span class="o">::</span><span class="na">getConnection</span><span class="p">()</span><span class="o">-&gt;</span><span class="na">getLastExecutedQuery</span><span class="p">();</span> </span></pre></div> </td></tr></table>
Propel, Symfony

YAML

Symfony 1.x : Increase timeout

1
2
3
4
5
6
7
# In apps/APP_NAME/config/factories.yml

all:
  user:
    class: myUser
    param:
      timeout: 7200 # 2h
https://snipt.net/embed/42b3f7ddbc2c4e2c1660b1521779fefd/
https://snipt.net/raw/42b3f7ddbc2c4e2c1660b1521779fefd/
42b3f7ddbc2c4e2c1660b1521779fefd
yaml
YAML
7
2016-09-21T06:49:44
True
False
True
Sep 03, 2012 at 12:37 PM
/api/public/snipt/46648/
symfony-1x-increase-timeout
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="c1"># In apps/APP_NAME/config/factories.yml</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="l-Scalar-Plain">all</span><span class="p-Indicator">:</span> </span><span id="L-4"><a name="L-4"></a> <span class="l-Scalar-Plain">user</span><span class="p-Indicator">:</span> </span><span id="L-5"><a name="L-5"></a> <span class="l-Scalar-Plain">class</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">myUser</span> </span><span id="L-6"><a name="L-6"></a> <span class="l-Scalar-Plain">param</span><span class="p-Indicator">:</span> </span><span id="L-7"><a name="L-7"></a> <span class="l-Scalar-Plain">timeout</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">7200</span> <span class="c1"># 2h</span> </span></pre></div> </td></tr></table>
Symfony, timeout

PHP

Symfony 1.x : Generate URL in controller

1
2
3
<?php

$url = $this->getController()->genUrl("@user_route", true);
https://snipt.net/embed/7d4e0a5fef26679ec5d074d0e41fdad6/
https://snipt.net/raw/7d4e0a5fef26679ec5d074d0e41fdad6/
7d4e0a5fef26679ec5d074d0e41fdad6
php
PHP
3
2016-09-21T06:49:48
True
False
True
Sep 02, 2012 at 05:45 AM
/api/public/snipt/46602/
symfony-1x-generer-une-url-dans-une-action
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="nv">$url</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">getController</span><span class="p">()</span><span class="o">-&gt;</span><span class="na">genUrl</span><span class="p">(</span><span class="s2">&quot;@user_route&quot;</span><span class="p">,</span> <span class="k">true</span><span class="p">);</span> </span></pre></div> </td></tr></table>
Symfony, action, url
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.