Why is this Symfony annotation not working?

Before I start, I should mention that this is&nbsp;<strong>Symfony 2.8.25</strong>. (I just started working on this code base, and once we get some critical issues resolved, we'll be upgrading.)

Before I start, I should mention that this is Symfony 2.8.25. (I just started working on this code base, and once we get some critical issues resolved, we'll be upgrading.)

I have an existing class using annotations with a number of routes that work fine.

I added a new one, and I get a 404 on that one every time. I did a console cache:clear which did not help. When I did a console debug:route, the new Routes appear in the list. But I still get a 404 on them, while the others in the same source file work.

All the routes use a POST, the working and non-working ones.

The routing.yml looks like this:

app:
    resource: '@AppBundle/Controller/'
    type: annotation

logout:
path: /logout

The class looks like this:

<?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Entity\Environment;
use AppBundle\Entity\Instance;
use AppBundle\Entity\Migration;
use AppBundle\Entity\UserActivity;
use AppBundle\Entity\Task;
use AppBundle\Form\Environment\EnvironmentType;
use AppBundle\Services\Api;
use AppBundle\Utils\HashRequest;

class EnvironmentController extends Controller
{
...
/**
*
* @Route("/api/envtype/add", name="api_envtype_add")
*
*/
public function addEnvtypeAction(Request $request){
...

When I try another route from this same class, it works. But not this new one.

I tried renaming the route, and that made no difference. I checked the annotation comment for TABs, since that's a (semi-)known bug in older versions. No TABs in the annotation.

This annotation looks to me exactly like the others that work. (None of them have a @return, for example.)

PostMan reports No route found for "POST /api/envtype/add"

I am completely out of ideas.

Top Vue.js Developers in USA

Top Vue.js Developers in USA

Vue.js is an extensively popular JavaScript framework with which you can create powerful as well as interactive interfaces. Vue.js is the best framework when it comes to building a single web and mobile apps.

We, at HireFullStackDeveloperIndia, implement the right strategic approach to offer a wide variety through customized Vue.js development services to suit your requirements at most competitive prices.

Vue.js is an open-source JavaScript framework that is incredibly progressive and adoptive and majorly used to build a breathtaking user interface. Vue.js is efficient to create advanced web page applications.

Vue.js gets its strength from the flexible JavaScript library to build an enthralling user interface. As the core of Vue.js is concentrated which provides a variety of interactive components for the web and gives real-time implementation. It gives freedom to developers by giving fluidity and eases the integration process with existing projects and other libraries that enables to structure of a highly customizable application.

Vue.js is a scalable framework with a robust in-build stack that can extend itself to operate apps of any proportion. Moreover, vue.js is the best framework to seamlessly create astonishing single-page applications.

Our Vue.js developers have gained tremendous expertise by delivering services to clients worldwide over multiple industries in the area of front-end development. Our adept developers are experts in Vue development and can provide the best value-added user interfaces and web apps.

We assure our clients to have a prime user interface that reaches end-users and target the audience with the exceptional user experience across a variety of devices and platforms. Our expert team of developers serves your business to move ahead on the path of success, where your enterprise can have an advantage over others.

Here are some key benefits that you can avail when you decide to hire vue.js developers in USA from HireFullStackDeveloperIndia:

  • A team of Vue.js developers of your choice
  • 100% guaranteed client satisfaction
  • Integrity and Transparency
  • Free no-obligation quote
  • Portal development solutions
  • Interactive Dashboards over a wide array of devices
  • Vue.js music and video streaming apps
  • Flexible engagement model
  • A free project manager with your team
  • 24*7 communication with your preferred means

If you are looking to hire React Native developers in USA, then choosing HireFullStackDeveloperIndia would be the best as we offer some of the best talents when it comes to Vue.js.

Add CSS to DomPDF

I've got this code to export some data into a pdf. And I would like to add css from an external css file (which is not mentionned in the html used)

I've got this code to export some data into a pdf. And I would like to add css from an external css file (which is not mentionned in the html used)

/*********************************** Export PDF ****************************************************/
if($request->query->get('exportPDF')!= null){
    // Configure Dompdf according to your needs
    $pdfOptions = new Options();
    $pdfOptions->set('defaultFont', 'Arial');
    // Instantiate Dompdf with our options
    $dompdf = new Dompdf($pdfOptions);
    // Retrieve the HTML generated in our twig file
    $html = $this->renderView('dashboard/user_table.html.twig', [
        'users' => $users
    ]);
    // Load HTML to Dompdf
    $dompdf->loadHtml($html);
    // (Optional) Setup the paper size and orientation 'portrait' or 'portrait'
    $dompdf->setPaper('A3', 'landscape');
    // Render the HTML as PDF
    $dompdf->render();
    // Output the generated PDF to Browser (force download)
    $dompdf->stream("exportUsers.pdf", [
        "Attachment" => true
    ]);
}

The user_table.html is only a file with a <table>

who has some class from a css file loaded in an other template. That means for DomPDF the file who contains the css is unkown and, as a result I have a table with no css in my pdf. I've tried to add the stylesheet in my html directly but the import isn't working like that neither. But I don't want to add it in the html anyway, the css is loaded is a more hight level template.

How to add external files (like bootstrap etc etc) from this structure ? I do not know if this is even possible. Thanks for the help ;)

Symfony 3.4 and Doctrine events - is it possible to redirect the user if an exception is thrown?

I'm building an e-commerce site that talks to Stripe's API during a set of&nbsp;prePersist,&nbsp;preUpdate, and&nbsp;preRemove&nbsp;Doctrine events. Unfortunately, the&nbsp;<a href="https://symfony.com/doc/3.4/event_dispatcher.html" target="_blank">documentation for Symfony events</a>&nbsp;doesn't really have anything on error/exception handling within events.

I'm building an e-commerce site that talks to Stripe's API during a set of prePersist, preUpdate, and preRemove Doctrine events. Unfortunately, the documentation for Symfony events doesn't really have anything on error/exception handling within events.

Ideally, I'd log the exception, and then redirect the user to a safe route (maybe the one that dispatched the event, or maybe a catch-all error page) with a relevant error message (flash message). Is that possible? If so, how would I do that from within an event?

How to use a custom collection in Symfony 4

I want to use a custom collection class for my Symfony 4 application. The following scenario is an example of what I am trying to achieve:

I want to use a custom collection class for my Symfony 4 application. The following scenario is an example of what I am trying to achieve:

I have a post collection class which has some utility for filtering and mapping data.

class PostArrayCollection extends ArrayCollection implements PostCollectionInterface
{
    public function mapTitles()
    {
        return $this->map(function (Post $post) {
            return $post->getTitle();
        });
    }
public function filterPublishedAfterDate(DateTime $from)
{
    return $this-&gt;filter(function (Post $post) use ($from) {
        return $post-&gt;publishedDate() &gt; $from;
    });
}

}

Also the user class which is a Doctrine Entity.

class User
{
/**
* @ORM\OneToMany(targetEntity="App\Entity\Post", mappedBy="post", cascade={"persist"})
*/
private $posts;

public function __construct()
{
    $this-&gt;posts = new PostArrayCollection();
}

public function getPosts(): PostCollectionInterface
{
    return $this-&gt;posts;
}

}

Then there is a method in a helper or controller which will access the user's data like the following:

public function showPublishedPostTitlesForUser(User $user)
{
$publishedPostTitles = $user->getPosts()
->filterPublishedAfterDate(new DateTime())
->mapTitles();

// Render the titles...

}

The above works when creating a new object by hand, for example in a unit test. But it will not work when loading the entity from the repository, because then the collections will be filled with Doctrine\ORM\PersistentCollection objects.

My question now is, how do I configure my app so I can use a custom persistent collection (for example PersistentPostCollection) when loading entities?

I did find this page https://www.doctrine-project.org/projects/doctrine-collections/en/latest/lazy-collections.html#lazy-collections, but I cannot find how to integrate this into Symfony 4.

Note: The above scenario is a simple example for the sake of keeping this question short and simple to get into. I am aware that this whole problem can be avoided when using a repository to get the correct data. But that is not what I am looking for here. This question is about understanding what is possible with Doctrine collections in Symfony 4.