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/
/raw/5270bdbab797dafc8122d8a75dd329b0/
5270bdbab797dafc8122d8a75dd329b0
php
PHP
6
2016-12-31T12:45:13
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></span><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