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

Getting error for undefined index in CodeIgniter
Request::Secure() not work with Asset()
Symfony Class Not Found Exception in Laravel Auditing (5)
groupBy within withCount closure (Laravel 5.3.26)
Use multiple name for an input type
How to review changes before making a record go live. Laravel, PHP
Adding “Related Products” to a custom tab in WooCommerce
Other files than php files not being processed; php-fpm
File request returns error 500
Display Banner after mysql first result
spl_autoload_register couldn't get “use” namespace
How do I retrieve an array value created in a PHP function?
Add space before question mark and exclamation mark
Set timezone according to different country locale wise in php
WordPress: Ajax response overwrites the whole page
PHP file temporarily unavailable

Categories

HOME
knockout.js
libgdx
angular-ui-grid
activemq
ant
autocomplete
cryptography
liferay-7
heuristics
getopenfilename
csrf
angular4
mpu6050
webstore
orange-api
bnf
tomcat8
scala-ide
robolectric
http-authentication
workday
fluent-migrator
device
exchange-server-2010
environment
sendmessage
splunk-query
guice
source-insight
knights-tour
mongoengine
code-rally
telephonymanager
widestring
jqgrid-asp.net
latexml
gcal
windows-media-player
cloudwatch
return-type
django-static-precompiler
nslayoutconstraint
nivo-slider
clrs
gmaps.js
openerp-6
nrf51
wildfly-9
dmarc
sharepoint-apps
jemdoc
utf-16
mercurial-extension
gulp-uglify
currency-exchange-rates
helm
ruby-on-rails-4.1
asp.net-web-api-helppages
dynamics-ax-2012-r2
algebraixlib
ocmockito
camus
findersync
maven-shade-plugin
hp-idol-ondemand
loginview
angular-ui-select
box2dweb
xulrunner
flipboard
pre
profiles
facebook-game-groups
mute
virtual-channel
playorm
workflow-manager-1.x
multidrop-bus
will-paginate
office-automation
asp.net-mvc-views
gaelyk
ccnet-config
aspbutton
bucket
fuzzy-comparison
tso
word-automation

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