php


Slim Controller Request, response and args not available


What I need is : Use a custom class to receive a HTTP Request and deal with it.
What I have so far:
$app->group('/user', function () use ($app) {
$app->post('/login', Auth::class . ':login');
}
And in my Auth Class:
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
// also tried: use Slim\Http\Request; use Slim\Http\Response;
class Auth {
protected $container;
public function __construct(&$c) {
$this->container = $c;
}
public function login(Request $request, Response $response, $args) {
// NEED TO GET GET/POST/PUT Params here
// When I Try to print $request, $response or $args, it returns empty
}
My code shows in the function login what I need : get the http params, and the request/response/args params. ( I want to implement many functions in one class, I mean, I don't want to use __invoke())
Another thing I don't understand is, if I do something like
return $response->withJson($somearraydata,200);
the variable $response actually works. Why?
Thanks for any help!
I think I have figured it out,
$args are never set,but request and response are.
and, to get params, I could do:
$request->getParsedBody()['attribute']
Hope this helps someone. :)

Related Links

PHP taking user input and formatting output (dates)
how to get the date for promotion from mysql using php / dynamic price
page/2/ Error 404 not custom query
Auto one-to-one model in Laravel
Warning: PHP Startup: Unable to load dynamic library apc.so
Schema describes boolean, string found instead when I create list through Mailchimp API
Braintree PHP SDK cURL exception
Shortcut for echo “<pre>”;print_r($myarray) inside foreach laravel
load default page from sub folder index page using .htaccess php
Parse error: syntax error, unexpected '"', expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) [duplicate]
How to remove items with certain length from array in php
PHP running multiple scripts concurrently
Laravel can't grab inputs from form to send out email
Find array key where value contains a specific value
Redirecting duplicated pages in WordPress template
Show Duplicate Values ​in Mysql

Categories

HOME
scroll
antd
dry
braintree
vsts-build
tcp
lvm
azure-data-lake
stored-procedures
anchor
hspi
gtk
azure-graph-api
heuristics
parsley.js
nsstring
vimeo
jpa-2.0
multiple-tables
clr
angular2-highcharts
error-logging
azure-machine-learning
anova
uislider
environment
multi-dimensional-scaling
clipboard
uilocalnotification
tf-idf
django-import-export
amazon-cloudtrail
publishing
quickcheck
nest
orchardcms-1.8
subclassing
mv
cloudera-quickstart-vm
uipickerview
rightnow-crm
intellij-lombok-plugin
ol3-google-maps
scala-breeze
uiautomatorviewer
karabiner
iptv
maven-jaxb2-plugin
popen
portability
d3v4
finder
bigdecimal
streamwriter
tablespace
fuzzer
static-methods
yii2-model
highlighting
apple-configurator
persistent-object-store
android-expansion-files
deeplink
msgpack
mixins
css-paged-media
alwayson
whitespace-language
quercus
fuseesb
prism-4
kognitio-wx2
jolie
jquery-mobile-flipswitch
stripe.net
incognito-mode
hyperloglog
fileshare
sqlbindparameter
jchartfx
profiles
xsd2code
ember-table
ax
.net-remoting
days
asp.net-mvc-3-areas
android-authenticator
gitx
playorm
nsmutablestring
popup-blocker
coordinate
thejit
mmc3
expression-web
git-log
explicit
ccnet-config
mysqli-multi-query
html-components
spring-modules
acceleration

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App