I have a really weird problem. I've search already the whole web for the solution and found nothing.
I am not newbie in PHP.
I use Lumen in my application. To send the data I use Postman.
The problem is:
$request->file() and $request->allFiles() returns NULL.
But if I use PHP $_FILES then it shows all.
Route:
$router->post('/import/create', 'CalendarController#importCreate');
Controller:
public function importCreate(Request $request)
{
// Get uploaded CSV file
$files = $request->allFiles();
return response($files);
}
This is what I get back:
{
"files": [
{}
]
}
(empty json array)
But if I do like this:
return response($_FILES);
Then it works:
{
"files": {
"name": [
"logo.png"
],
"type": [
"image/png"
],
"tmp_name": [
"/tmp/phpjcjN4q"
],
"error": [
0
],
"size": [
7278
]
}
}
What we can exclude::
I use good Request import:
use Illuminate\Http\Request;
php.ini settings are OK:
The file I tried to upload has only 7KB, so its not the problem.
I use POST, and not PUT, so its not the problem.
Postman Request:
What I also noticed that $request->all() and $request->input() both returns also NULL, even if I post anything.
As I said I am not newbie in this, and I really appreciate your help.
Anyone got any clue?
Thanks in advance.
Ok, it has been fixed somehow. Don't know how, don't know when.
I updated composer dependencies with composer update but I'm not sure if that was the case.
we have our Spartacus project set up to fetch the context from the basesites request. A sample response can be seen here:
{
"baseSites" : [ {
"defaultLanguage" : {
"isocode" : "sl"
},
"geoRecommended" : false,
"showTeaser" : true,
"stores" : [ {
"currencies" : [ {
"isocode" : "EUR"
} ],
"defaultCurrency" : {
"isocode" : "EUR"
},
"defaultLanguage" : {
"isocode" : "sl"
},
"languages" : [ {
"isocode" : "sl"
} ],
} ],
"uid" : "ung-site-si",
"urlEncodingAttributes" : [ "languageCountry" ],
"urlPatterns" : [ "(?i)^https?://localhost(:[\\d]+)?/rest/.*$", "(?i)^https?://[^/]+/(sl-SI)/?.*$" ]
}, ...
]
We have two basesites set up at the moment. The urlPatterns are used to find the correct baseSite. Then the context(baseSite, language, currency) is set in our custom occ-loaded-config-converter. So we are not using any static context or fetching it from the URL, but getting the context from the response of the basesites request.
The site-context-interceptor then subscribes to e.g. this.languageService.getActive() and then sets the correct context (language, currency) for the backend requests:
/rest/v2/ung-site-rs/cms/pages?fields=DEFAULT&pageType=ContentPage&pageLabelOrId=/shoppster-akcija&lang=sr&curr=RSD
Before the Spartacus Upgrade to 2.0 this worked fine. Right after the context was set from the basesites request, the subscription in the site-context-interceptor was triggered an the right context sent with the subsequent backend requests. Now after upgrading to 2.1, the context is not set on time anymore. So the first few backend requests are sent with the wrong context (default USD, en) and then at some point in time, the subscriptions are triggered an the correct context is set.
This may be related to this change:
https://sap.github.io/spartacus-docs/technical-changes-version-2/#context-change-action-not-dispatched-on-the-initial-setting-of-the-value
Is it now not possible anymore to use the basesites request to set the context?
As discussed in comments: bumping to the latest patch version 2.1.4 has fixed the issue.
I have unit tests with Cache mocks. It worked well before update laravel to 6.0
After update I ran my tests and got an exception
Mockery\Exception\BadMethodCallException: Received
Mockery_2_Illuminate_Cache_CacheManager::driver(), but no expectations
were specified
Cache::shouldReceive('get')
->once()
->with('table_3_'.config('constants.league.premier').'_'.config('constants.sex.female'))
->andReturn(json_encode([
[
'id' => $team1->id,
'place' => 1
],
[
'id' => $team2->id,
'place' => 8
],
[
'id' => $team3->id,
'place' => 11
],
]));
$this->artisan('passport:transfer');
I have found the answer here - Laravel Feature Testing. Cache mocking not working! CacheManager::driver(), but no expectations were specified
but I don't understand why before update the test was ok
So i normally work on external servers, but decided to set up a local environment in the form of WAMPserver on my windows 8.1 computer.
From (git bash) console, i can run lessc without a problem, but when i install Yii2, and attempt to process .less it says it can't find the command.
AssetConverter command 'lessc "C:/wamp/www/basic/web/css/site.less" "C:/wamp/www/basic/web/css/site.css" --no-color --source-map' failed with exit code 1:
STDOUT:
STDERR:
'lessc' is not recognized as an internal or external command,
operable program or batch file.
Now as far as i can tell, this should work. In fact, when i run that same command from console it works just fine. Am i missing a step here? Any help would be appreciated.
I fixed it just now.
How should you do?
Make sure you can run lessc in cmd windows.If you can't,install it with node.js Install lessc with node.js
Make sure lessc path in system path.Mine is C:\Users\l7861\AppData\Roaming\npm or you can type where lessc in cmd windows to find it.
Make sure you can see lessc path in path_info().If you can't restart your apache server.
Finally you don't need to add addassetManager in config never~~~~~
This below is a discovery process.
I just thought it is a bug on yii2 at first.So I debug it with Phpstrom.And I saw this line:path\to\vendor\yiisoft\yii2\web\AssetConverter.php 91
$command = Yii::getAlias($command);
$command = strtr($command, [
'{from}' => escapeshellarg("$basePath/$asset"),
'{to}' => escapeshellarg("$basePath/$result"),
]);
$descriptor = [
1 => ['pipe', 'w'],
2 => ['pipe', 'w'],
];
$pipes = [];
$proc = proc_open($command, $descriptor, $pipes, $basePath);
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
foreach ($pipes as $pipe) {
fclose($pipe);
}
$status = proc_close($proc);
if ($status === 0) {
Yii::trace("Converted $asset into $result:\nSTDOUT:\n$stdout\nSTDERR:\n$stderr", __METHOD__);
} elseif (YII_DEBUG) {
throw new Exception("AssetConverter command '$command' failed with exit code $status:\nSTDOUT:\n$stdout\nSTDERR:\n$stderr");
} else {
Yii::error("AssetConverter command '$command' failed with exit code $status:\nSTDOUT:\n$stdout\nSTDERR:\n$stderr", __METHOD__);
}
return $status === 0
}
Only if $status is not 0,then you got a error message.
And that usually means $command has something wrong.
When I ran to here, I could see it is 'lessc "path/to/frontend/web/less/main.less" "path/to/frontend/web/less/main.css" --no-color';
And I ran it in cmd.Then css file was created by it.
I wrote a similar code below like that function
$command='lessc "path/to/frontend/web/less/main.less" "path/to/frontend/web/less/main.css" --no-color';
$basePath="path/to/frontend/web";
$descriptor = [
1 => ['pipe', 'w'],
2 => ['pipe', 'w'],
];
$pipes = [];
$process = proc_open($command, $descriptor, $pipes /* $cwd, $env */ );
print_r($pipes);
$stdout = stream_get_contents($pipes[1]);
echo mb_convert_encoding($stdout, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5' );
$stderr = stream_get_contents($pipes[2]);
echo mb_convert_encoding($stderr, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5' );
if (is_resource($process)) {
fwrite($pipes[1], '<?php print_r($_ENV); ?>');
fclose($pipes[1]);
echo stream_get_contents($pipes[2]);
fclose($pipes[2]);
$return_value = proc_close($process);
echo "command returned $return_value\n";
}
And ran it in browser.Then I got a error "lessc is not recognized as an internal or external command".
So I chang config file config/main.php,
return [
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
'assetManager' => [
'converter' => [
'class' => 'yii\web\AssetConverter',
'commands' => [
'less' => ['css', 'lessc {from} {to} --no-color'],
],
],
],
],
'name' => 'FavorTGD',
];
I got a same a same message.So I check out php_info(),there no lessc program in path.there there.That all you need is just restart your apache.
And delete assetManager in main.php
Ended up fixing it by changing the command to reference the lessc.cmd directly
'assetManager'=>[
'converter' => [
'class' => 'yii\web\AssetConverter',
'commands' => [
'less' => ['css', 'c:\path\to\lessc.cmd {from} {to} --no-color'],
],
],
],
Not to happy about the fix, because this means i will need to change my settings when i go 'live', but nothing else worked. I tried symlinking it into the yii directory, commands directory, etc.. but no good.
I have installed yii2-admin module, located in /vendor/mdmsoft/yii2-admin but I don't want it to load its own asset bundle. It there any way to disable this module asset bundle?
Yes, it's possible and even mentioned in official docs here. One way to do it is through application config:
return [
// ...
'components' => [
'assetManager' => [
'bundles' => [
'mdm\admin\AdminAsset' => false,
],
],
],
];
Another way - during runtime through component:
\Yii::$app->assetManager->bundles['mdm\admin\AdminAsset'] = false;