PHP code example of kenny1911 / ajax-bundle
1. Go to this page and download the library: Download kenny1911/ajax-bundle library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kenny1911 / ajax-bundle example snippets
use Kenny1911\AjaxBundle\Attribute\Ajax;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
final class PostController
{
public function __construct(
private readonly PostRepository $postRepository,
) {}
#[Ajax]
public function getPost(string $id): Post
{
$post = $this->postRepository->find($id) ?? throw new NotFoundHttpException();
return new Post(
id: $post->getId(),
title: $post->getTitle(),
);
}
}