I am new in zf2 and I want to get parameter from url. But when I write
if($this->getRequest()->isGet()) {
$get = $this->params()->fromQuery();
}
print_r($get);
in controller it returns empty array. How I get parameter from url? Here is my url:
http://test.zeptosystems.com/event/create/46/1396465200/1
I want to get 46. How can I get this parameter?
In controller you can do that with Params plugin:
$this->params()->fromQuery();
But fromQuery
returns standard GET
params from part ?var=value&var2=somevalue
. Because you have nice urls you should use
$this->params()->fromRoute();
See Reference of Params class or ZF2 Manual Controller's plugins page for more details
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class FooController extends Controller
{
// stuff
public function showAction(){
// and to show http req
$req = new Request();
$foo = $req->get('foo');
return new Response('Get Parameter -> '.$foo);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.