0

when i try to get the parameter from url its returning nothing

Here is my url : http://localhost/myapp/web/dailydata/payment/amount/1000

Here is my symfony script :

use Symfony\Component\HttpFoundation\Request;
.
.
public function MyAction()
{
    $request = $this->getRequest();
    $amount = $request->request->get('amount');
    echo 'Amount ='.$amount;
    exit;
}
2
  • 1
    If you have .../{amount} in your route definition then $request->attributes->get('amount') or just function myAction($amount) Commented Aug 7, 2016 at 23:20
  • Thanks $request->attributes->get('amount') works for me. Commented Aug 8, 2016 at 5:15

2 Answers 2

1

You need to define a proper route in you routing.yml file like this:

my_action:
    path:      /dailydata/payment/amount/{amount}
    defaults:  { _controller: <bundle>:<controller>:My }

If you don't specify which part of the route is a parameter you can't access it from the action. Replace the various gaps (proper URL, bundle and controller) where necessary.

Sign up to request clarification or add additional context in comments.

Comments

0
use Symfony\Component\HttpFoundation\Request;
.
.
public function MyAction()
{
    $request = $this->getRequest();
    $amount =$request->attributes->get('amount'); //replace this line in above code
    echo 'Amount ='.$amount;
    exit;
}

1 Comment

Glad it is working. Just as a side note, consider injecting the request: MyAction(Request $request)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.