-
Notifications
You must be signed in to change notification settings - Fork 1
ServerRequest: getAttribute Example
Terry L edited this page Jun 20, 2020
·
4 revisions
Shieldon\Psr7\ServerRequest
Extends Request.
Retrieve a single derived request attribute.
-
param
string
name*
The attribute name. -
param
mixed
default= null
Default value to return if the attribute does not exist. -
return
mixed
Example:
This example extends to the previous one.
$ip = $serverRequest->getAttribute('ip_address');
$session = $serverRequest->getAttribute('session');
// paymentStatus does not exist.
$paymentStatus = $serverRequest->getAttribute('paymentStatus', 'failed');
echo $ip
// Outputs: 127.0.0.1
echo $session['user_role'];
// Outputs: admin
echo $paymentStatus;
// Outputs: failed
composer require shieldon/psr-http
Shieldon PSR HTTP implementation written by Terry L. from Taiwan.