问题描述
嗨,我想检查以下验证:
func UsersGetAll(c *fiber.Ctx) error {
db := database.DBConn
users := []entities.User{}
records := db.Preload(clause.Associations).Find(&users)
if records.Error != nil {
log.Println(records.Error)
return c.Status(500).SendString(records.Error.Error())
}
return c.JSON(records.Value)
}
解决方法
您已经在PHP领域中,正在运行PHP ..您无法启动其他PHP。同样,单引号'
不会扩展变量。
我正在根据您的项目做出的许多假设
使用您的逻辑,您可以这样做:
echo '<div id="msg">' . (isset($msg) ? $msg : '') . '</div>';
但最好不要在未设置变量时仅输出div
if(isset($msg)) {
echo "<div id=\"msg\">$msg</div>";
}
有关您要实现的目标的更多信息,将使我对最佳实践有更多的了解。
您的编辑建议仍然让您尝试在php中启动新的php块
您建议使用以下命令编辑我的答案(很奇怪):
echo '<div class="container">
<form action="includes/ajax.php" id="profilePictureUpload" class="dropzone">
<div class="fallback">
<input name="file" type="file" multiple />
</div>
</form>
<h1>Gallery</h1>
<div class="alert alert-warning my-2">
<i class="fa fa-2x fa-exclamation-circle float-right"></i>
<ol class="m-0">
<li>Image uploading limit is 5.</li>
<li>One image not more then 5MB.</li>
</ol>
</div>
<div id="msg"><?php echo isset($msg)?$msg:''; ?></div>
</div>';
如果您已阅读我发布的内容,则需要用我发布的内容替换该1 <div id="msg"...
。你检查了吗?