【问题标题】:Access multiple GET parameters in Slim Framework v3在 Slim Framework v3 中访问多个 GET 参数
【发布时间】:2016-11-19 04:58:43
【问题描述】:

我有一个脚本代码将重定向到

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

并且生成的示例 url 是

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

序列化值来自WordPress的Contact Form 7插件。

在我的苗条路线中,我有

<?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?
});

我得到的是这个

就像第一条路线正在为此工作,但不是我想要的路线。

如何在我的路由中访问这些参数,例如姓名、电子邮件以及所有这些参数?

任何帮助将不胜感激。

【问题讨论】:

    标签: php wordpress url slim


    【解决方案1】:

    您可以使用$request-&gt;getQueryParams() 访问查询字符串参数。 IE。像

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

    或更短的版本。

    $email = $request->getQueryParam("your-email");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-27
      • 1970-01-01
      • 2017-05-22
      • 2013-05-31
      相关资源
      最近更新 更多