snipt

Ctrl+h for KB shortcuts

PHP

GET & POST in Symfony

1
2
3
4
5
6
7
<?

$request = $this->getRequest();
$request->query->get('page'); // get a $_GET parameter
$request->request->get('page'); // get a $_POST parameter

?>
https://snipt.net/embed/48f02226866b5811751b627b91c3463c/
https://snipt.net/raw/48f02226866b5811751b627b91c3463c/
48f02226866b5811751b627b91c3463c
php
PHP
7
2016-09-30T06:41:04
True
False
True
Feb 20, 2013 at 10:58 AM
/api/public/snipt/56124/
get-post-in-symfony
<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="cp">&lt;?</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="nv">$request</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">getRequest</span><span class="p">();</span> </span><span id="L-4"><a name="L-4"></a><span class="nv">$request</span><span class="o">-&gt;</span><span class="na">query</span><span class="o">-&gt;</span><span class="na">get</span><span class="p">(</span><span class="s1">&#39;page&#39;</span><span class="p">);</span> <span class="c1">// get a $_GET parameter</span> </span><span id="L-5"><a name="L-5"></a><span class="nv">$request</span><span class="o">-&gt;</span><span class="na">request</span><span class="o">-&gt;</span><span class="na">get</span><span class="p">(</span><span class="s1">&#39;page&#39;</span><span class="p">);</span> <span class="c1">// get a $_POST parameter</span> </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
symfony
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.