我使用Symfony4 + Api平台开发了一个API,并根据在GET中发送的参数创建了一条路径来检索命令,除了调用该路径时,我收到一条无法识别的错误消息:>
{ “ @context”:“ / api / contexts / Error”, “ @type”:“ hydra:Error”, “ hydra:title”:“发生错误”, “ hydra:description”:“由于无效的标识符配置而未找到”, “跟踪”:[ {
这是我定义路线的班级:
<!-- MASTER TEXT FIELD WHERE DATA ENTERED IS REFLECTED IN ALL TEXT FIELDS
CREATED IN THE LOOP -->
<input class="form-control" type="text" name="add0" id="add0"
onkeyup="sync()">
<!-- END -->
<form action="add.php" method="GET">
<div class="row">
$counter = 1;
while ($res = pg_fetch_assoc($result)) {
?>
<!-- THIS ENTIRE DIV GETS SHOWN/HID WHEN THE SLIDER IS MOVED -->
<div class="col-md-2 show-hide">
<input type="text" value="<?php echo $res['size']; ?> " name="size[]" id= "
<?php echo $res['size']; ?>" readonly style="background-color: #F5F5F5;"
class="form-control" />
<!-- DYNAMIC TEXT FIELDS ARE DISPLAYED HERE -->
<div id="addition<?php echo $counter; ?>">
</div>
</div>
<!-- END OF DIV THAT GETS SHOWN/HID -->
<?php
$counter = $counter + 1;}
</div>
<button type="submit" value="submit">Apply</button>
<script>
$(document).ready(function () {
<!-- CODE TO ASSIGN DYNAMIC ID'S TO INPUT FIELDS -->
for (var i = 1; i < 9; i++)
{
$('#addition' + i).append('<input class="form-control" type="text"
name="add[]" id="add' + i + '" />');
}
}
</script>
<!-- CODE FOR SLIDER -- >
$('#slider').slider({
min: 36,
max: 50,
step: 1,
values: [36, 50],
range: true,
slide: function (event, ui) {
$.each(ui.values, function (i, v) {
$('input.value').eq(i).val(v);
});
<!-- SCRIPT TO HIDE AND SHOW DATA -->
$('.show-hide').each(function (idx, div) {
var $div = $(div);
var value = $div.children().first().val();
if (value < ui.values[0] || value > ui.values[1]) {
<!-- TO ASSIGN 0 WHEN THE FIELDS -->
$div.find('input:nth-of-type(2)').val('0');
$div.hide();
}
else {
<!-- THE FIELD IS CLEARED-->
$div.find('input:nth-of-type(2)').val('');
$div.show();
}});
}});
<!-- END OF HIDE/SHOW SCRIPT -->
$('input.value').change(function () {
var $this = $(this);
$('#slider').slider('values', $this.attr('data-index'),
$this.val());
});
<!-- END CODE FOR SLIDER -->
});
您对我忘记了什么有想法吗?谢谢您的帮助。
答案 0 :(得分:0)
我做了一些调试... 在vendor / api-platform / core / src / Identifier / IdentifierConverter.php:49中,引发了初始异常:资源“ My \ Model”没有标识符。
我的模型在yaml文件中配置。在那里,我添加了属性“ id”,并将其标记为“ identifier = true”。当然,该属性以及setter和getter必须存在。
resources:
My\Model:
properties:
id:
identifier: true
希望对您有所帮助!
答案 1 :(得分:0)
我遇到了同样的问题,发现指定为evaluateEmptyValues: function(reference, originalReference) {
var vm = this;
console.log('reference', reference);
console.log('Before --> ' + reference.data.articleTitle);
// Get keys and values of both reference objects
referenceLength = Object.entries(reference).length;
originalReferenceLength = Object.entries(originalReference).length;
if (referenceLength == originalReferenceLength) {
try {
for (var prop in reference) {
if (reference[prop] != undefined || reference[prop] != null) {
if (typeof (reference[prop]) == 'string' && reference[prop].trim() == '') {
reference[prop] = originalReference[prop];
}
if (typeof(reference[prop]) == 'object' && typeof(originalReference[prop]) == 'object') {
console.log('reference[prop]', reference[prop]);
console.log('originalReference[prop]', originalReference);
vm.evaluateEmptyValues(reference[prop], originalReference[prop]);
}
if (Array.isArray(reference[prop]) && typeof Array.isArray(originalReference[prop])) {
reference[prop].forEach((item, index) => vm.evaluateEmptyValues(item, originalReference[prop][index]));
}
} else {
reference[prop] = originalReference[prop];
}
}
} catch(err) {
console.log(err);
}
}
console.log('After --> ' + reference.data.articleTitle);
//
// console.log('Original --> ' + originalReference.data.articleTitle);
}
的路由要求itemOperations
在该路由中,否则它将不起作用。您可以通过将其设置为{id}
来解决它,但是实际上可以对给定对象进行操作(API平台也对其进行了测试)。
希望这会有所帮助:)