Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access multiple GET parameters in Slim Framework v3

I have a script code which will redirect to

http://localhost:8080/generated/sample/ + $('form.wpcf7-form').serialize();

and a sample generated url of that is

http://localhost:8080/generated/sample/_wpcf7=222&_wpcf7_version=4.5.1&_wpcf7_locale=en_US&_wpcf7_unit_tag=wpcf7-f222-p37-o1&_wpnonce=35162dc550&your-name=Robert+Soriano&your-email=sorianorobertc%40gmail.com&mobile-number=39174535417

The serialized value is from the Contact Form 7 plugin of WordPress.

In my slim route I have

<?php
// Routes

$app->get('/{name}', function ($request, $response, $args) {
    // Sample log message
    $this->logger->info("Slim-Skeleton '/' route");

    // Render index view
    return $this->renderer->render($response, 'index.phtml', $args);
});

$app->get('/generated/sample/', function ($request, $response, $args) {
    return $args['your-email'];
    // How to access different parameters here?
});

And what I get is this

enter image description here

It's like the first route is working for that but not the route that I want.

How can I access those parameters like the name, email, and all of it in my route?

Any help would be much appreciated.

like image 771
wobsoriano Avatar asked Apr 29 '26 07:04

wobsoriano


1 Answers

You can access query string parameters with $request->getQueryParams(). Ie. something like

$params = $request->getQueryParams();
$email = $params["your-email"];

Or shorter version.

$email = $request->getQueryParam("your-email");
like image 187
Mika Tuupola Avatar answered Apr 30 '26 20:04

Mika Tuupola



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!