如何在PHP中以原始形式从POSTMAN application / json接收多个值“Array”(How to receive multiple values “Array” from POSTMAN application/json in raw form in PHP)
当我尝试在PHP中接收多个数组值进行验证时,我遇到了一些问题。 我有这个对象与POSTMAN原始形式,
application/json
:{ "name":"create_insert_new_delivery", "param":{ "email_of_shipment_owner":"hi@example.com", "shipment_type ":"B", "item_name": ["50", "60"], "item_weight ": ["H", "I"], "item_length": ["70", "90"] } }
当我尝试接收$ item_name = $ this-> validateParameter('item_name',$ this-> param ['item_name'],ARRAY,true); 就像收到下面的两个字符串一样,我得到了这个
**错误:**
[04-Jul-2018 13:16:58 UTC] PHP Parse错误:语法错误,意外',',期待'('在/home/osconliz/public_html/Osconlizapicall/api.php第304行
接收代码如下。
LINE 302
$email_of_shipment_owner = $this->validateParameter('email_of_shipment_owner', $this->param['email_of_shipment_owner'], STRING, true);
LINE 303
$shipment_type = $this->validateParameter('shipment_type', $this->param['shipment_type'], STRING, true);
LINE 304
$item_name = $this->validateParameter('item_name', $this->param['item_name'], ARRAY, true);
LINE 305
$item_weight = $this->validateParameter('item_weight', $this->param['item_weight'], ARRAY, true);
LINE 306
$item_length = $this->validateParameter('item_length', $this->param['item_length'], ARRAY, true);
但STRINGS正确收到:
public function validateParameter($fieldName, $value, $dataType, $required = true){ switch ($dataType) { case BOOLEAN: if (!is_bool($value)){ $this->throwError(VALIDATE_PARAMETER_DATATYPE, "Datatype is not valid for " . $fieldName . ' it should be boolean.'); } break; case INTEGER: if (!is_numeric($value)){ $this->throwError(VALIDATE_PARAMETER_DATATYPE, "Datatype is not valid for " . $fieldName . ' it should be integer.'); } break; case STRING: if (!is_string($value)){ $this->throwError(VALIDATE_PARAMETER_DATATYPE, "Datatype is not valid for " . $fieldName . ' it should be string.'); } break; case ARRAY: if (!is_array($value)){ $this->throwError(VALIDATE_PARAMETER_DATATYPE, "Datatype is not valid for " . $fieldName . ' it should be array.'); } break; default: $this->throwError(VALIDATE_PARAMETER_DATATYPE, "Datatype is not valid for " . $fieldName); break; } return $value; }
收到后我想验证这样的数据
if ($this->item_category == ""){ } else { if ($this->item_category == "A" || $this->item_category == "B" || $this->item_category == "C" || $this->item_category == "D" || $this->item_category == "E" || $this->item_category == "F" || $this->item_category == "G" || $this->item_category == "H") { } else { $this->throwError(INVALID_DATA_TTT, "Invalid item category"); exit(); } }
I am having a little issue when I try to receive multiple array values in PHP for validation. I have this object with values in POSTMAN raw form,
application/json
:{ "name":"create_insert_new_delivery", "param":{ "email_of_shipment_owner":"hi@example.com", "shipment_type ":"B", "item_name": ["50", "60"], "item_weight ": ["H", "I"], "item_length": ["70", "90"] } }
When I try to receive $item_name = $this->validateParameter('item_name', $this->param['item_name'], ARRAY, true); like the two strings below are received I get this
**ERROR : **
[04-Jul-2018 13:16:58 UTC] PHP Parse error: syntax error, unexpected ',', expecting '(' in /home/osconliz/public_html/Osconlizapicall/api.php on line 304
The receiving code below.
LINE 302
$email_of_shipment_owner = $this->validateParameter('email_of_shipment_owner', $this->param['email_of_shipment_owner'], STRING, true);
LINE 303
$shipment_type = $this->validateParameter('shipment_type', $this->param['shipment_type'], STRING, true);
LINE 304
$item_name = $this->validateParameter('item_name', $this->param['item_name'], ARRAY, true);
LINE 305
$item_weight = $this->validateParameter('item_weight', $this->param['item_weight'], ARRAY, true);
LINE 306
$item_length = $this->validateParameter('item_length', $this->param['item_length'], ARRAY, true);
but the STRINGS are received properly :
public function validateParameter($fieldName, $value, $dataType, $required = true){ switch ($dataType) { case BOOLEAN: if (!is_bool($value)){ $this->throwError(VALIDATE_PARAMETER_DATATYPE, "Datatype is not valid for " . $fieldName . ' it should be boolean.'); } break; case INTEGER: if (!is_numeric($value)){ $this->throwError(VALIDATE_PARAMETER_DATATYPE, "Datatype is not valid for " . $fieldName . ' it should be integer.'); } break; case STRING: if (!is_string($value)){ $this->throwError(VALIDATE_PARAMETER_DATATYPE, "Datatype is not valid for " . $fieldName . ' it should be string.'); } break; case ARRAY: if (!is_array($value)){ $this->throwError(VALIDATE_PARAMETER_DATATYPE, "Datatype is not valid for " . $fieldName . ' it should be array.'); } break; default: $this->throwError(VALIDATE_PARAMETER_DATATYPE, "Datatype is not valid for " . $fieldName); break; } return $value; }
After receiving I want validate data like this
if ($this->item_category == ""){ } else { if ($this->item_category == "A" || $this->item_category == "B" || $this->item_category == "C" || $this->item_category == "D" || $this->item_category == "E" || $this->item_category == "F" || $this->item_category == "G" || $this->item_category == "H") { } else { $this->throwError(INVALID_DATA_TTT, "Invalid item category"); exit(); } }
原文:https://stackoverflow.com/questions/51175225
最满意答案
是。
从文档 :
contacts(联系人) :这是当主机出现问题(或恢复)时应该通知的联系人短名单。 多个联系人应该用逗号分隔。 如果您希望通知只发送给几个人并且不想配置联系人组,那么这很有用。 您必须在每个主机定义中至少指定一个联系人或联系人组。
contact_groups :这是联系人组短名称的列表,当该主机出现问题(或恢复)时应该通知联系人组的短名称。 多个联系人组应该用逗号分隔。 您必须在每个主机定义中至少指定一个联系人或联系人组。
其实 - 现在我复制,我不太确定它正确地描述答案。
你也可能想看看对象继承 。
但是,简短的答案仍然是肯定的 。
Yes.
From the documentation:
contacts: This is a list of the short names of the contacts that should be notified whenever there are problems (or recoveries) with this host. Multiple contacts should be separated by commas. Useful if you want notifications to go to just a few people and don't want to configure contact groups. You must specify at least one contact or contact group in each host definition.
contact_groups: This is a list of the short names of the contact groups that should be notified whenever there are problems (or recoveries) with this host. Multiple contact groups should be separated by commas. You must specify at least one contact or contact group in each host definition.
Actually - now that I copy that I'm not so sure it describes the answer properly.
You may also want to look at Object Inheritance.
But, the short answer is still a yes.
相关问答
更多-
是。 从文档 : contacts(联系人) :这是当主机出现问题(或恢复)时应该通知的联系人短名单。 多个联系人应该用逗号分隔。 如果您希望通知只发送给几个人并且不想配置联系人组,那么这很有用。 您必须在每个主机定义中至少指定一个联系人或联系人组。 contact_groups :这是联系人组短名称的列表,当该主机出现问题(或恢复)时应该通知联系人组的短名称。 多个联系人组应该用逗号分隔。 您必须在每个主机定义中至少指定一个联系人或联系人组。 其实 - 现在我复制,我不太确定它正确地描述答案。 你也可能想 ...
-
警报是通过服务还是主机警报发出的? 可能是您的服务notification_interval设置为1小时。 Are the alerts coming through service or host alerts? It could be that your service notification_interval is set to 1 hour.
-
连接被防火墙阻止,或者Nagios服务器不在“允许的主机”字段的nsc.ini文件中。 确保Windows防火墙上的端口以及Nagios服务器和客户端之间的任何其他网络过滤器都已打开。 The connection is getting blocked either by a firewall or your Nagios server is not in the nsc.ini file in the "allowed hosts" field. Make sure that port is open o ...
-
使用ndoutils-2.0.0将Nagios中的数据存储到MariaDB中(Storing data from Nagios into MariaDB using ndoutils-2.0.0)[2023-06-12]
所有你需要做的是升级你的NDOUtils到版本2.1.0为了得到它的工作! All you need to do is upgrade your NDOUtils to version 2.1.0 in order to get it working! -
厨师和Nagios间隔(Chef and Nagios intervals)[2021-10-29]
看看https://github.com/opscode-cookbooks/nagios/blob/master/templates/default/services.cfg.erb#L14我想通过简单地定义那些属性就像现有的属性一样 - 只需要认识到json格式化。 Looking at https://github.com/opscode-cookbooks/nagios/blob/master/templates/default/services.cfg.erb#L14 I would guess ... -
基本问题是command_name值与原始/标准check_http命令冲突。 你有(至少)几个选择: 设置唯一的command_name ,例如check_http_8082 。 定义一个命令来检查作为参数传递的任意端口上的http。 例如 define command{ command_name check_http_port command_line /usr/lib64/nagios/plugins/check_http -H $HOSTADDRESS$ -p $ARG1$ } T ...
-
这对我有用: location /pnp4nagios { alias /usr/share/pnp4nagios/html; } location ~ ^(/pnp4nagios.*\.php)(.*)$ { root /usr/share/pnp4nagios/html; include /etc/nginx/fastcgi_params; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PAT ...
-
谢谢stevieb你让我走在正确的道路上。 这似乎工作: use Nagios::Config; use Nagios::Object::Config; use Data::Dumper; use feature 'say'; use Getopt::Long; Getopt::Long::Configure('bundling'); GetOptions( "C|config=s" => \$OPTION{'config'} ); my $objects; $objects = Nagi ...
-
您的游戏专门针对您的master服务器: - name: Configure Nagios server hosts: master ... 因此,任务将仅针对此节点(或称为master的库存组中的多个节点)运行。 然后,您似乎对如何从您希望监视的其他服务器获取变量(在您的情况下slaves库存组中的所有内容)感到困惑。 inventory_hostname将完成它在锡上所说的内容 - 它将为您提供运行任务的服务器的主机名。 在这种情况下,只有永远是master 。 但是,你在这条线上的正确轨道: ...
-
ambari使用nagios(does ambari use nagios)[2022-05-05]
Nagios和Ganglia被用作独立服务,为Ambari 1.7.0及更低版本提供信息。 从2.0版开始,Ambari开始使用他自己的监控服务Ambari Metrics和Ambari Alerts 。 Naglia与Ganglia的支持被取消。 Nagios and Ganglia were used as standalone services, to provide info for Ambari 1.7.0 and less. Since version 2.0, Ambari moved to ...