我使用PSR-2代码样式代码.
当我大多数时候使用Codesniffer检查文件时,我收到以下错误.
332 | ERROR | [x] Expected 1 newline at end of file; 0 found
Run Code Online (Sandbox Code Playgroud)
很明显如何解决这个问题.我需要知道的是,如果PhpStorm有办法添加1 newline at end of file
我已经加载了预定义的样式,Settings -> Editor -> Code Style -> PHP -> Set From -> PSR-1/PSR-2
并且还使用了相应Reformat Code
的更改CS.
除了新线以外,一切都是固定的.我错过了什么吗?
我有以下两个功能
public function myEndpoint(){
$this->logger->debug('Started');
$this->guzzle->requestAsync('post', 'http://myurl.com/doNotWait')->wait();
$this->logger->debug("I shouldn't wait");
}
public function doNotWait(){
sleep(10);
$this->logger->debug("You shouldn't wait");
}
Run Code Online (Sandbox Code Playgroud)
现在我需要在日志中看到的是:
Started
I shouldn't wait
You shouldn't wait
Run Code Online (Sandbox Code Playgroud)
但我所看到的
Started
You shouldn't wait
I shouldn't wait
Run Code Online (Sandbox Code Playgroud)
我还尝试使用以下方法:
方式#1
public function myEndpoint(){
$this->logger->debug('Started');
$this->guzzle->requestAsync('post', 'http://myurl.com/doNotWait', ['synchronous' => false])->wait();
$this->logger->debug("I shouldn't wait");
}
Run Code Online (Sandbox Code Playgroud)
方式#2
public function myEndpoint(){
$this->logger->debug('Started');
$this->guzzle->requestAsync('post', 'http://myurl.com/doNotWait');
$queue = \GuzzleHttp\Promise\queue()->run();
$this->logger->debug("I shouldn't wait");
}
Run Code Online (Sandbox Code Playgroud)
但结果永远不是理想的结果.任何的想法?我正在使用Guzzle 6.x.
在CakePHP 2.x $order
中,模型中有一个属性.所以我使用这个属性来全局排序我的数据.因此,例如假设我需要在我的Country
模型中的视图中显示带有国家/地区的选择框,用于添加行:
$order = 'Country.country DESC';
Run Code Online (Sandbox Code Playgroud)
然后当我从任何控制器获取国家时,按国家名称而不是由id
任何其他字段排序的数据.这对于选择框特别有用.在CakePHP 3.x上,我似乎无法在文档中找到任何类似的参考.
当我获取数据并且不在每个查找中使用order选项时,我可以做些什么来使我的数据全局排序?
我在服务器上有我的私人存储库。在我的作曲家文件中,我有以下 JSON:
"repositories": [
{
"type": "composer",
"url": "myrepositoryurl"
}
]
Run Code Online (Sandbox Code Playgroud)
一切都很好。如果我运行以下命令。
composer config repositories vcs myrepositoryurl
Run Code Online (Sandbox Code Playgroud)
我收到作曲家的错误:
[InvalidArgumentException]
Setting repositories does not exist or is not supported by this command
Run Code Online (Sandbox Code Playgroud)
如果我将命令更改为
composer config repositories.name vcs myrepositoryurl
Run Code Online (Sandbox Code Playgroud)
一切正常,我在composer.json 文件中得到了以下更新:
"repositories": {
"name": {
"type": "composer",
"url": "myrepositoryurl"
}
}
Run Code Online (Sandbox Code Playgroud)
这两者之间有什么实际区别吗?如果我不想为我的存储库 URL 设置名称怎么办?我可以从命令行执行此操作吗?
通过以下方式将消息传递给 flash 很简单:
$this->Flash->error(__('The user could not be saved. Please, try again.'));
Run Code Online (Sandbox Code Playgroud)
但是当出现更多错误时:
$package->errors();
Run Code Online (Sandbox Code Playgroud)
我只使用一个简单的 foreach 循环:
foreach ($package->errors() as $error=>$value)
{
foreach ($value as $single_error)
{
$error_array[] = ($single_error);
}
}
Run Code Online (Sandbox Code Playgroud)
然后我将它传递给一个 flash 元素:
$this->Flash->custom($error_array, [
'key' => 'custom']);
Run Code Online (Sandbox Code Playgroud)
并在闪存消息中:
if ($message > 0) {
foreach ($message as $m) {
echo h($m).'<br />';
}
} else {
echo h($message);
}
Run Code Online (Sandbox Code Playgroud)
我想知道这是处理一系列验证错误的更好方法。
我拥有的是什么
$string = 'one;two;three;four;five;six;seven;eight;nine;ten';
Run Code Online (Sandbox Code Playgroud)
我需要的是:
$array = [
['one', 'two', 'three'],
['four', 'five', 'six'],
['seven', 'eight', 'nine'],
['ten'],
];
Run Code Online (Sandbox Code Playgroud)
基本上字符串可以有无限的值.
php ×5
cakephp ×2
cakephp-3.0 ×2
arrays ×1
asynchronous ×1
codesniffer ×1
composer-php ×1
guzzle ×1
guzzle6 ×1
json ×1
php-5.5 ×1
phpstorm ×1
psr-2 ×1
regex ×1
repository ×1
split ×1
terminal ×1
validation ×1