本文整理汇总了PHP中Slim\Http\Request::getQueryParams方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getQueryParams方法的具体用法?PHP Request::getQueryParams怎么用?PHP Request::getQueryParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\Http\Request
的用法示例。
在下文中一共展示了Request::getQueryParams方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
/**
* __invoke is called by slim when a route matches
* @param $request Request
* @param $response Response
* @param $args array
* *
* @return $response \Slim\Http\Response
*/
public function __invoke(Request $request, Response $response, array $args)
{
$this->response = $response;
//check for api key
$queryParams = $request->getQueryParams();
if (isset($queryParams['api_key'])) {
$userData = UserModel::getUserWithApiKey($queryParams['api_key']);
if ($userData !== false) {
$this->currentUser = new User($userData);
}
}
$this->response = $this->response->withHeader('Content-type', 'application/json');
}
示例2: viewPages
/**
* Generate pagination
*
* @return string
*/
public function viewPages($totalData, $limit)
{
$parameter = '';
$query_params = $this->request->getQueryParams();
if ($query_params) {
foreach ($query_params as $key => $param) {
if ($key != 'page') {
if ($parameter == '') {
$parameter .= '?' . $key . '=' . $param;
} else {
$parameter .= '&' . $key . '=' . $param;
}
}
}
}
if ($parameter == '') {
$parameter .= '?page=';
} else {
$parameter .= $parameter . '&page=';
}
if (empty($query_params['page'])) {
$page = 1;
} else {
$page = $query_params['page'];
}
$count_page = ceil($totalData / $limit);
$elements[] = '<ul class="pagination">';
if ($page > 1) {
$elements[] = '<li>';
$elements[] = '<a href="' . $parameter . ($page - 1) . '" aria-label="Previous">';
$elements[] = '<span aria-hidden="true">«</span>';
$elements[] = '</a>';
$elements[] = '</li>';
}
for ($i = 1; $i <= $count_page; $i++) {
if ($i == $page) {
$elements[] = ' <li><a href="#">' . $i . '</a></li>';
} else {
$elements[] = '<li><a href="' . $parameter . $i . '">' . $i . '</a></li>';
}
}
if ($page < $count_page) {
$elements[] = '<li>';
$elements[] = '<a href="' . $parameter . ($page + 1) . '" aria-label="Previous">';
$elements[] = '<span aria-hidden="true">»</span>';
$elements[] = '</a>';
$elements[] = '</li>';
}
$elements[] = '</ul>';
return implode('', $elements);
}
示例3: authenticateCallback
public function authenticateCallback(Request $request, Response $response)
{
$code = $request->getQueryParams()['code'] ?? '';
try {
if (!$code) {
throw new \Exception('No access code provided.');
}
$token = $this->provider->getAccessToken('authorization_code', ['code' => $_GET['code']]);
$this->helper->setAccessToken(['access_token' => $token->getToken(), 'expires' => $token->getExpires()]);
return $response->withStatus(301)->withHeader('Location', '/' . self::AREA);
} catch (\Exception $ex) {
return $this->view->render($response, 'error.twig', ['error' => $ex->getMessage()]);
}
}
示例4: reportReg
public function reportReg(Request $req, Response $res)
{
$container = $this->slim->getContainer();
$db = $container->medoo;
$queryParams = $req->getQueryParams();
$cYear = $queryParams["year"] - 543;
$where = [];
$where["reg_date[>=]"] = $cYear . "-01-01 00:00:00";
$where["reg_date[<=]"] = $cYear . "-12-31 23:59:59";
$items = $db->select("person", "*", ["AND" => $where]);
$objWriter = $this->makeExcelBypersons($items);
// We'll be outputting an excel file
header('Content-type: application/vnd.ms-excel');
// It will be called file.xls
header('Content-Disposition: attachment; filename="reg-' . $queryParams["year"] . '.xls"');
// Write file to the browser
$objWriter->save('php://output');
exit;
}
示例5: accounts
public function accounts(Request $req, Response $res)
{
$container = $this->slim->getContainer();
$db = $container->medoo;
$queryParams = $req->getQueryParams();
$where = [];
$where["level"] = ["staff", "user"];
$total = $db->count("account", $where);
// count
// item per page
$perPage = 50;
$maxPage = ceil($total / $perPage);
$page = @$queryParams['page'] ? $queryParams['page'] : 1;
$start = ($page - 1) * $perPage;
$where["LIMIT"] = [$start, $perPage];
// end count
$where["ORDER"] = "id";
$items = $db->select("account", "*", $where);
return $container->view->render($res, "account/list.twig", ["form" => $queryParams, "items" => $items, "page" => $page, "maxPage" => $maxPage]);
}
示例6: error
/**
* Simulate "error".
*
* Usage:
* - <code>/test/error?debug=1</code> For testing develop mode (`displayErrorDetails = true`)
* - <code>/test/error</code> For testing production mode (`displayErrorDetails = false`)
*
* @param Request $request The most recent Request object
*
* @throws Exception
*/
public function error(Request $request)
{
$params = $request->getQueryParams();
$this->settings['displayErrorDetails'] = (bool) ($params['develop'] ?? false);
throw new Exception("Test");
}
示例7: personsSearch
public function personsSearch(Request $req, Response $res)
{
$container = $this->slim->getContainer();
$db = $container->medoo;
// $session = $container->session;
// $segment = $session->getSegment("login");
// $segment->set("username", "papangping");
// $session->commit();
$oldersService = XMLService::getInstance("olders");
$cripplesService = new CrippleService($db);
$disavantagedsService = new DisavantagedService($db);
$scholarsService = new ScholarService($db);
$olders = $oldersService->gets();
$cripples = $cripplesService->gets();
$disavantageds = $disavantagedsService->gets();
$scholars = $scholarsService->gets();
$queryParams = $req->getQueryParams();
$where = [];
if (@$queryParams["is_older"] == "0" || @$queryParams["is_older"] == "1") {
$where["is_older"] = $queryParams["is_older"];
}
if (!empty($queryParams["cripple_id"])) {
$where["person_cripple.cripple_id"] = $queryParams["cripple_id"];
}
if (!empty($queryParams["disa_id"])) {
$where["person_disavantaged.disavantaged_id"] = $queryParams["disa_id"];
}
if (!empty($queryParams["scho_id"])) {
$where[".person_scholar.scholar_id"] = $queryParams["scho_id"];
}
if (!empty($queryParams["keyword"])) {
$where["OR"] = [];
$where["OR"]["first_name[~]"] = "%" . $queryParams["keyword"] . "%";
$where["OR"]["last_name[~]"] = "%" . $queryParams["keyword"] . "%";
$where["OR"]["card_id[~]"] = "%" . $queryParams["keyword"] . "%";
}
if (count($where) > 0) {
$where = ["AND" => $where];
}
$join = ["[>]person_cripple" => ["id" => "person_id"], "[>]person_disavantaged" => ["id" => "person_id"], "[>]person_scholar" => ["id" => "person_id"]];
$column = ["person.id", "person.card_id", "person.first_name", "person.last_name", "person.reg_date", "person.die_date", "person.birth_date", "person.is_older"];
$total = $db->count("person", $join, "person.id", $where);
// count
// item per page
$perPage = 50;
$maxPage = ceil($total / $perPage);
$page = @$queryParams['page'] ? $queryParams['page'] : 1;
$start = ($page - 1) * $perPage;
$where["LIMIT"] = [$start, $perPage];
// end count
$where["GROUP"] = "person.id";
$where["ORDER"] = "person.card_id";
$items = $db->select("person", $join, $column, $where);
$this->buildItems($items);
// hardcode for empty page
if (count($where) <= 3) {
$items = [];
}
return $container->view->render($res, "person/list_search.twig", ["form" => $queryParams, "items" => $items, "olders" => $olders, "cripples" => $cripples, "disavantageds" => $disavantageds, "scholars" => $scholars, "page" => $page, "maxPage" => $maxPage]);
}
示例8: json
/**
* Output JSON info about the video.
*
* @param Request $request PSR-7 request
* @param Response $response PSR-7 response
*
* @return Response HTTP response
*/
public function json(Request $request, Response $response)
{
$params = $request->getQueryParams();
if (isset($params['url'])) {
try {
$video = $this->download->getJSON($params['url']);
return $response->withJson($video);
} catch (\Exception $e) {
return $response->withJson(['success' => false, 'error' => $e->getMessage()]);
}
}
}
示例9: authenticateCallback
/**
* Sends request:
* curl --data "code=[GET->code]
* &grant_type=authorization_code
* &client_id=[client_id]
* &client_secret=[client_secret]
* &redirect_uri=[url_of_this_function]"
* https://www.googleapis.com/oauth2/v3/token
*
* Gets response:
* [
* 'code' => '4/PTIwf4eUb3ajdD21_access_code'
* 'scope' => 'https://www.googleapis.com/auth/drive.readonly'
* ]
* @param Request $request
* @param Response $response
* @return \Psr\Http\Message\MessageInterface|\Psr\Http\Message\ResponseInterface
*/
public function authenticateCallback(Request $request, Response $response)
{
$code = $request->getQueryParams()['code'] ?? '';
try {
if (!$code) {
throw new \Exception('No access code provided.');
}
$client = new Client();
$params = ['code' => $code, 'grant_type' => 'authorization_code', 'client_id' => $this->config->getClientId(), 'client_secret' => $this->config->getClientSecret(), 'redirect_uri' => $this->helper->getCallbackUrl(self::AREA)];
$response = $client->post($this->config->getTokenUri(), ['form_params' => $params]);
$json = json_decode($response->getBody(), true);
$this->helper->setAccessToken($json);
if (!isset($json['access_token'])) {
throw new \Exception("Access token not returned.");
}
return $response->withStatus(301)->withHeader('Location', '/' . self::AREA);
} catch (\Exception $ex) {
return $this->view->render($response, 'error.twig', ['error' => $ex->getMessage()]);
}
}
示例10: editAlbum
private function editAlbum(Request $request, Response $response)
{
$queryParams = $request->getQueryParams();
if (isset($queryParams['id'])) {
/* @var \App\models\Album $album */
$album = $this->model->load('Album');
$output = $album->filter(['id' => $queryParams['id'], 'user_id' => $this->user['id']])->fetch();
if ($output) {
$output['action'] = self::ACTION_EDIT;
$output['isPublicOptions'] = $album->getIsPublicOptions();
$output['photoId'] = $request->getParam('pid', 0);
return $this->renderer->render($response, 'admin/edit_album.html', $output);
} else {
return $response->withStatus(302)->withHeader('Location ', $this->router->pathFor('admin_index'));
}
} else {
return $response->withStatus(302)->withHeader('Location ', $this->router->pathFor('admin_index'));
}
}
示例11: filterRequestMethod
/**
* This provide a method-overwrite for GET and POST request
*
* @param \Slim\Http\Request $req
* @return \Slim\Http\Request
*/
protected function filterRequestMethod(Request $req)
{
$method = strtoupper($req->getMethod());
$params = [];
if ($method == 'GET') {
$params = $req->getQueryParams();
} elseif ($method == 'POST') {
$params = $req->getParsedBody();
}
if (isset($params['_method'])) {
$req = $req->withMethod($params['_method']);
}
return $req;
}