I'm new to symfony but mostly api-platform. So I looked in the api-platform to learn more about it. I readed it for the big part, overwhelming in information. But I just couldn't find a way to use openAPI in a way to get edit post data. I'm also using doctrine and SQLite
So what I mean by edit post data. I installed api-platform and got it working (it looks like, this). I can POST data with my api-platform at the url www.localhost/api and then select POST under Role and then "try out". I made a small table in doctrine, so the JSON i send to it is;
{
"role": "string"
}
So that works, it adds the data in my SQLite DB. But I want to edit this data in PHP. But I just can't find out how to retrieve this JSON and edit the data i get from the JSON.
What I have is; A Entity and Repository named Role and RoleRepository. And I readed a controller is not needed to edit the data with api-platform. But I cant find anywhere how to edit the data.
So how do I edit the data I get from the JSON?
Edit: If you are wondering what my entity Role looks like it is;
<?php
namespace App\Entity;
use App\Repository\RoleRepository;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ApiResource()
* @ORM\Entity(repositoryClass=RoleRepository::class)
*/
class Role
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $role;
public function getId(): ?int
{
return $this->id;
}
public function getRole(): ?string
{
return $this->role;
}
public function setRole(string $role): self
{
$this->role = $role;
return $this;
}
}
And RoleRepository
<?php
namespace App\Repository;
use App\Entity\Role;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method Role|null find($id, $lockMode = null, $lockVersion = null)
* @method Role|null findOneBy(array $criteria, array $orderBy = null)
* @method Role[] findAll()
* @method Role[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class RoleRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Role::class);
}
// /**
// * @return Role[] Returns an array of Role objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('r')
->andWhere('r.exampleField = :val')
->setParameter('val', $value)
->orderBy('r.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/*
public function findOneBySomeField($value): ?Role
{
return $this->createQueryBuilder('r')
->andWhere('r.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}