Slim PHP and GET Parameters

后端 未结 9 517
猫巷女王i
猫巷女王i 2021-01-30 03:56

I\'m playing with Slim PHP as a framework for a RESTful API, and so far it\'s great. Super easy to work with, but I do have one question I can\'t find the answer to. How do I gr

9条回答
  •  孤街浪徒
    2021-01-30 04:26

    Probably obvious to most, but just in case, building on vip's answer concerning Slim 3, you can use something like the following to get the values for the parameters.

            $logger = $this->getService('logger');
            $params = $request->getQueryParams();
            if ($params)  {
                foreach ($params as $key => $param)     {
                    if (is_array($param))   {
                        foreach ($param as $value)  {
                            $logger->info("param[" . $key . "] = " . $value);
                        }
                    }
                    else    {
                        $logger->info("param[" . $key . "] = " . $param);
                    }
                }
            }
    

提交回复
热议问题