Symfony Api平台规范化上下文组日期时间属性问题

时间:2020-04-26 19:36:42

标签: symfony datetime normalization api-platform.com

在对组使用Normalizer时,我遇到了奇怪的问题。看起来日期时间属性有问题。

在ApiResource上使用#include <iostream> using namespace std; int main() { string Inum; cout << "Enter the number to start the calculator" << '\n'; cin >> Inum; bool Decision = true; int Inumv_1 = 0; if (Inum [0] == '0') Decision = false; for (int Inumv_2 = 0; Inumv_2 < Inum.length() && Decision; Inumv_2++) if (!(Inum [Inumv_2] >= '0' && Inum [Inumv_2] <= '9')) { Decision = false; Inumv_1 = Inumv_2; break; } if (Decision) { system("cls"); cout << "---------------------" << '\n'; cout << "Calculator is Running" << '\n'; cout << "---------------------" << '\n'; char numvalidation[256] = { '\0' }; double var1, var2; var1 != '\0'; beginning: cout << "Enter the First value: "; cin >> var1; cout << "Enter the second value: "; cin >> var2; cout << "What do you want to do?" << endl; cout << ">> + :Addition" << endl; cout << ">> - :Subtraction" << endl; cout << ">> * :Multiplication" << endl; cout << ">> / :Division" << endl; cout << "Please chose one of the option below" << endl; char decision; cout << "Decision: "; cin >> decision; system("cls"); switch (decision) { case '+': cout << var1 << " + " << var2 << " = " << "" << (var1 + var2) << endl; break; case '-': cout << var1 << " - " << var2 << " = " << "" << (var1 - var2) << endl; break; case '*': cout << var1 << " * " << var2 << " = " << "" << (var1 * var2) << endl; break; case '/': if (var2 == !0) cout << var1 << " / " << var2 << " = " << "" << (var1 / var2) << endl; else cout << "The value you have entered is invalid because you cannot divide any number by zero" << endl; break; default: cout << "Only Number are Allowed, try again "; return 0; } { cout << "Do you want to continue using the Calculator? (Y/N)" << endl; char decision2; cin >> decision2; if (decision2 == 'y' || decision2 == 'Y') goto beginning; if (decision2 == 'N' || decision2 == 'n') cout << "Thank you for using our program" << endl; else return 0; } } else cout << "Invalid Input and contains: [" << Inum [Inumv_1] << "] Calculator can't be started. Try again." << '\n'; } 和/或在操作上使用normalizationContext时会发生问题。

normalization_context

结果属性<?php namespace App\Entity; use ApiPlatform\Core\Annotation\ApiResource; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\Groups; /** * @ApiResource( * collectionOperations={ * "get"={ * "normalization_context"={ * "datetime_format"="Y-m-d\TH:i:sP", * "groups"={"bookmarkdata:collection:read"} * } * } * }, * itemOperations={ * "get" * }, * normalizationContext={"groups"={"bookmarkdata:read"}} * ) * @ORM\Entity(repositoryClass="App\Repository\BookmarkDataRepository") */ class BookmarkData { /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") * @Groups({"bookmarkdata:read", "bookmarkdata:collection:read"}) */ private $id; /** * @ORM\Column(type="string", length=2048, nullable=true) * @Groups({"bookmarkdata:read", "bookmarkdata:collection:read"}) */ private $screenshot; /** * @ORM\Column(type="string", length=2048) * @Groups({"bookmarkdata:read", "bookmarkdata:collection:read"}) */ private $dump; /** * @ORM\Column(type="datetime") * @Groups({"bookmarkdata:read", "bookmarkdata:collection:read"}) */ private $created_at; /** * @ORM\Column(type="datetime", nullable=true) */ private $updated_at; public function getId(): ?int { return $this->id; } public function getScreenshot(): ?string { return $this->screenshot; } public function setScreenshot(?string $screenshot): self { $this->screenshot = $screenshot; return $this; } public function getDump(): ?string { return $this->dump; } public function setDump(string $dump): self { $this->dump = $dump; return $this; } public function getCreatedAt(): ?\DateTimeInterface { return $this->created_at; } public function setCreatedAt(\DateTimeInterface $created_at): self { $this->created_at = $created_at; return $this; } public function getUpdatedAt(): ?\DateTimeInterface { return $this->updated_at; } public function setUpdatedAt(?\DateTimeInterface $updated_at): self { $this->updated_at = $updated_at; return $this; } } 被忽略。

created_at

我正在使用Docker。 我的依赖。

{
    "@context": "/api/contexts/BookmarkData",
    "@id": "/api/bookmark_datas",
    "@type": "hydra:Collection",
    "hydra:member": [
        {
            "@id": "/api/bookmark_datas/1",
            "@type": "BookmarkData",
            "id": 1,
            "screenshot": "This is screen",
            "dump": "This is dump"
        }
    ],
    "hydra:totalItems": 1
}

0 个答案:

没有答案