Pjax in Yii 2 with POST request - post

How can I use Pjax in Yii 2 with POST request?
I tried to do it like that but page restarts anyway:
<?php Pjax::begin(['id' => 'some-id', 'clientOptions' => ['method' => 'POST']]);?>
...
some content
...
<?=Html::a('', ['cart/cart'],
['class'=>'close1',
'data' => [
'method' => 'post',
'params' => [
'idCartToDelete' => $product->idCart,
],
]
]
)
?>
...
some content
...
<?php Pjax::end(); ?>

You're close to solving your issue. To your Html::a parameters add:
'data-pjax' => 0,
And you will have a link that does not redirect to another page.

Related

getting wrong user with laravel sanctum

I am using Laravel Sanctum to provide a personal access token to my clients.
I am using these guards in auth.php:
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'client' => [
'driver' => 'token',
'provider' => 'clients',
'hash' => false
]
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'clients' => [
'driver' => 'eloquent',
'model' => App\Models\Client::class,
],
],
I give my clients tokens using the following code:
$client = Client::find($id);
$token = $client->createToken('CLIENT_TOKEN');
but whenever I try to access the user with $request->user() I get the wrong user. while the token is completely different from what the retrieved user is.
I am using laravel-swoole package as my webserver.

How to send messages using AWS Pinpoint service using PHP SDK

Hi I am trying to send a message using AWS Pinpoint with the PHP SDK, but I am getting an error. Any ideas why? Here is my code:
$client = new PinpointClient([
'version' => 'latest',
'region' => 'us-east-1',
'credentials' => [
'key' => 'MYIAMAWSKEY',
'secret' => 'MYAWSSECRET',
]
]);
$result = $client->sendMessages([
'ApplicationId' => 'MyAppId',
'MessageRequest' => [
'Addresses' => [
'AnIOSDeviceToken' => [
'BodyOverride' => 'aaa',
'ChannelType' => 'APNS',
'RawContent' => 'bbb',
'Context' => ['ccc' => '222'],
'TitleOverride' => 'ddd',
],
],
],
'MessageConfiguration' => [
'APNSMessage' => [
'Action' => 'OPEN_APP',
'Body' => 'Hello',
'RawContent' => 'World',
'SilentPush' => false,
'Title' => 'Hello World!!!',
],
],
]);
I get the following error:
DeliveryStatus: 'PERMANENT_FAILURE'
StatusCode: 400
StatusMessage: Invalid notification: Notification is malformed
According to the API Docs, 'MessageConfiguration' needs to be inside the 'MessageRequest' field. Please make sure your input parameters fully match the documented API Parameter Syntax.

ZF2/3 catchall route with slug

I need one route to fetch page content out of my CMS by a slug. I thought I could easy create a configuration like the following but it seems that it only works with multiple parts in the route. My plan was to create a custom route, but if I don't get a match with the system routes I don't think I will get one with my custom route :)
So is there a way to do that?
Does not work
'router' => [
'routes' => [
'cms' => [
'type' => \Zend\Router\Http\Segment::class,
'options' => [
'route' => '/:slug',
'defaults' => [
'controller' => \Cms\Controller\PageController::class,
'action' => 'index'
]
]
]
]
];
Works
'router' => [
'routes' => [
'cms' => [
'type' => \Zend\Router\Http\Segment::class,
'options' => [
'route' => '/test/:slug', // <-- Here is the change
'defaults' => [
'controller' => \Cms\Controller\PageController::class,
'action' => 'index'
]
]
]
]
];
OK, forgett everything... I already had a segment route with the same format, but with some constraints. Therefore I got a 404 page. So everything works fine...

How to make a Guzzle post using query string parameters

In a Google Oauth2 implementation I'm trying to exchange an authorization code for tokens using a guzzle call.
The following guzzle call works fine and returns the expected values:
$result = $this->client->post(
'https://www.googleapis.com/oauth2/v3/token?code=<authorization_code>&redirect_uri=<redirect_uri>&client_id=<client_id>&client_secret=<client_secret>&grant_type=authorization_code')
->getBody()->getContents();
However this seems a dirty way to mount the post request.
I've tried the following way in order make it cleaner:
$result = $this->client->post(
'https://www.googleapis.com/oauth2/v3/token',
[
'query' =>
[
'code' => <authorization_code>,
'redirect_uri' => <redirect_uri>,
'client_id' => <client_id>,
'client_secret' => <client_secret>
'grant_type' => 'authorization_code',
]
]
)->getBody()->getContents();
However this second call generates a Malformed Json error message.
Any idea what I might be doing wrong or how can I debug what final url is being generated in the example above?
I tried without code parameter and it worked.
$client = new \GuzzleHttp\Client();
$response = $client->post('https://www.googleapis.com/oauth2/v3/token', [
'query' => [
'client_id' => '...apps.googleusercontent.com',
'client_secret' => 'secret',
'refresh_token' => 'token',
'grant_type' => 'refresh_token'
]
]);
$token = $response->getBody()->getContents()
Have you tried using arrays and http://php.net/json_encode

Yii2 MaskedInput with alias 'url' limits input to 60 characters

I am using the following code in Yii2:
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'link')->widget(MaskedInput::classname(), [
'clientOptions' => [
'alias' => 'url',
],
]) ?>
<?php ActiveForm::end(); ?>
It seems, that the input field is limited to 60 characters. How to remove this limitations?
See the URL example on: http://demos.krajee.com/masked-input
The limitation is in jquery.inputmask. See https://github.com/RobinHerbots/jquery.inputmask/issues/863. This limitation will disappear if the issue is solved and the new jquery.inputmask.js is included in Yii2 bower package.

Resources