1. Go to this page and download the library: Download api-code/base-symfony 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/ */
api-code / base-symfony example snippets
sh
# In a controller
/**
* Example with annotations
* @Route(
* name="demo_special",
* path="/demo/{id}/special",
* defaults={"_api_resource_class"=Product::class, "_api_item_operation_name"="specialdemo"}
* )
* @Method("GET")
*/
public function demoAction()
{
$em = $this->getDoctrine()->getManager();
$products = $em->getRepository(Product::class)->findAll();
return $products;
}
sh
// other uses
use Doctrine\ORM\EntityManager;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
final class ProductMailSubscriber implements EventSubscriberInterface
{
private $mailer;
private $em;
protected $authorizationChecker;
protected $token;
public function __construct(\Swift_Mailer $mailer, EntityManager $em, AuthorizationCheckerInterface $authorizationChecker, \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage $token_storage)
{
// Initilize vars!!!
}
public static function getSubscribedEvents()
{
return [
//KernelEvents::VIEW => [['sendMail', EventPriorities::POST_WRITE]],
KernelEvents::VIEW => [['accionDemo', EventPriorities::POST_WRITE]]
];
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.