Posts

Showing posts with the label Symfony

Add Extra Fields Using JMS Serializer Bundle

Answer : I've found the solution by myself, to add a custom field after the serialization has been done we've to create a listener class like this: <?php namespace Acme\DemoBundle\Listener; use JMS\DiExtraBundle\Annotation\Service; use JMS\DiExtraBundle\Annotation\Tag; use JMS\DiExtraBundle\Annotation\Inject; use JMS\DiExtraBundle\Annotation\InjectParams; use Symfony\Component\HttpKernel\Event\PostResponseEvent; use Acme\DemoBundle\Entity\Team; use JMS\Serializer\Handler\SubscribingHandlerInterface; use JMS\Serializer\EventDispatcher\EventSubscriberInterface; use JMS\Serializer\EventDispatcher\PreSerializeEvent; use JMS\Serializer\EventDispatcher\ObjectEvent; use JMS\Serializer\GraphNavigator; use JMS\Serializer\JsonSerializationVisitor; /** * Add data after serialization * * @Service("acme.listener.serializationlistener") * @Tag("jms_serializer.event_subscriber") */ class SerializationListener implements EventSubscriberInterface { /**...

Assetic Generating Links But No Files

Answer : You have 2 options when dealing with assets. The reason you do not see your assets physically in your computer is because you chose Option 1. Option 1: SYMFONY CAN PROCESS THE FILES DYNAMICALLY FOR YOU That means that each asset path generated in the dev environment is handled dynamically by Symfony. Therefore, Assetic generates paths to CSS and JavaScript files that don't physically exist on your computer. This is an internal Symfony controller that opens the files and serves back the content for you. Advantages: - Changes made on your assets take immediate effect - This is great in dev mode as Symfony generates the files dynamically for you Disadvantages: - This is not possible in prod mode as rendering each asset dynamically would be too slow - The assets won't be directly accessible on your computer (which is why you cannot find the file) - Can be quite slow if you are using a lot of filters, etc... To do this in dev mode, ju...