Symfony2 can't find route for an action - symfony

I'm doing a bundle with google drive api that lists files. I have in the IndexAction an if that sees if the user needs to give permission or already gave. If needs, then I get the url from google and redirect to that link.
In google console I put as redirect link:
www.googlebundle/firstTime
In my GoogleDriveController I've got the
public function firstTimeAction() {
(...)
}
And in my routing I got this:
FilesGoogleDriveBundle_firstTime:
pattern: /firstTime
defaults: { _controller: "FilesGoogleDriveBundle:GoogleDrive:firstTime" }
requirements: { _method: get }
FilesGoogleDriveBundle_homepage:
pattern: /Drive/{id}
defaults: { _controller: FilesGoogleDriveBundle:GoogleDrive:index }
But I get this error in prod.log:
[2012-11-26 16:50:14] request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /firstTime" (uncaught exception) at /var/www/Symfony/app/cache/prod/classes.php line 4564 [] []
Does anyone know what's happening?

First make sure that symfony see your router rule.
In project root directory put
php app/console router:debug | grep FilesGoogleDriveBundle_firstTime
You should get something like this
FilesGoogleDriveBundle_firstTime GET /firstTime
The last value is the URL for this action.

FilesGoogleDriveBundle_firstTime:
pattern: /firstTime
defaults: { _controller: FilesGoogleDriveBundle:GoogleDrive:firstTime }
requirements:
_method: GET
Try this.

seems like a cache problem, clear the cache for the prod environment:
php app/console cache:clear --env=prod

Related

How do I force a 404 from the symfony routing in YML without specifying a custom controller?

Problem to solve
I want to force to trigger a 404 for a certain specific route in symfony, without having to specify a custom controller that just throws the exception, and before the router continues to explore the rest of the routing file.
Can I say that in the routing.yml file for a specific route?
Context
I have this routing for form submitting in my travel agency:
POST /submit/{submitterForm}
where submitterForm can only take 2 values: purchase-trip and contact depending on if the visitor submits a form in a page where he is visiting a trip or from the contact page. For example POST /submit/contact would be valid.
I have this other route:
GET /{destinationSeoUri}/{tripSeoUri}
to display a specific trip for a destination. For example GET /thailand/trip-bangkok-beaches would be valid.
Limiting values from the router
This is the relevant extract of my routing.yml:
submit:
path: /submit/{submitterForm}
methods: [ POST ]
defaults: { _controller: AppBundle:DataSubmission:submit }
requirements:
submitterForm: purchase-trip|contact
trip:
path: /{destinationSeoUri}/{tripSeoUri}
methods: [ GET ]
defaults: { _controller: AppBundle:Trip:trip }
What I want
For any POST request with an invalid value of {submitterForm} in the route /submit/{submitterForm} I want that the system returns a 404 Not Found
It does not happen now because when the router does not match the submit route pattern, it still falls down to the next ones and then matches the trip pattern.
Then, the system says "okey, I have a route that matches, instead, this is only allowed for GET, so I'll respond a 405 Method not allowed".
This would hold true for something like POST /thailand/trip-bangkok-beaches but I want to specifically signal the client that if the POST matches the /submit/any-invalid-form-submitter-name it is then a Not Found.
Initial solution
To do so, I've inserted, in order, in the middle of the previous two, a catch-all for /submit/* like in this routing excerpt:
submit:
path: /submit/{submitterForm}
methods: [ POST ]
defaults: { _controller: AppBundle:DataSubmission:submit }
requirements:
submitterForm: purchase-trip|contact
submit_fallback:
path: /submit/{submitterForm}
methods: [ POST ]
defaults: { _controller: AppBundle:DataSubmission:notFound }
trip:
path: /{destinationSeoUri}/{tripSeoUri}
methods: [ GET ]
defaults: { _controller: AppBundle:Trip:trip }
This way, requesting to POST /submit/any-invalid-form-submitter-name is matched by the submit_fallback route.
The controller
The controller is a pretty simple "on-liner":
{
throw new NotFoundHttpException();
}
Preferred solution
I think I'm looking for something similar to this:
submit_fallback:
path: /submit/{submitterForm}
methods: [ POST ]
status: 404
So, questions
Is it possible for me to tell the submit_fallback something like: hey guy you don't need a _controller just because you have to send a 404 Not found (or any other status I would want) and nothing else.
If so, how?
Just add requirements onto your other route so that destinationSeoUri cannot equal submit. This should force that route to not match, and throw the 404 instead of the 405 error.
trip:
path: /{destinationSeoUri}/{tripSeoUri}
methods: [ GET ]
defaults: { _controller: AppBundle:Trip:trip }
requirements:
destinationSeoUri: "^(?!submit$)"

How to set correctly my routes files (url) with symfony2.5 with WAMP server

I set my route files in my Symfony2.5 project. But i have this problem when I launched my application with Wamp server (localhost on Windows):
No route found for "GET /" (from "http://localhost/girSymfony/web/")
404 Not Found - NotFoundHttpException
1 linked Exception: ResourceNotFoundException »
This is the url used when the application is lauched on WampServer: http://localhost/girSymfony/web/
When I tried with this URL http://localhost/girSymfony/web/I have the 404 error as mentioned above.
But if I try with this url: http://localhost/girSymfony/web/gir/homepage it works; I would like the application arrive and run directly on this url. How can i do that?
This is my Gir/WelcomeBundle/Ressource/config/routing.yml file code:
girWelcomeBundle_HomePage:
pattern: /homepage
defaults: { _controller: GirWelcomeBundle:HomePage:index }
requirements:
methods: GET
schemes:  https
And this my app/config/routing.yml file code:
GirWelcomeBundle:
resource: "#GirWelcomeBundle/Resources/config/routing.yml"
prefix: /gir
And here's my controller code for Gir/WelcomeBundle/Controller/HomePageController.php:
<?php
namespace Gir\WelcomeBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class HomePageController extends Controller
{
public function indexAction()
{
return $this->render('GirWelcomeBundle:HomePage:index.html.twig');
}
}
Like you can see, I set the routes files, but I just forgot something because I have the 404 error.
I think my application don't use the right direction and the right URL , how can I fix it ?
New edit: Note that I 've set WAMP and Symfony in order when I run my application I arrive directly on the HomePage index
You are on development environemt , you should have to use url like this
Example:
registration:
pattern: /registration
defaults: { _controller: UserBundle:Registration:registration }
http://localhost/girSymfony/web/app_dev.php/registration

Define route without ending slash when importing route in Symfony 2.5?

In file: HardCoreMore/HRAPIBundle/Resources/config/routing.yml
I have imported route like this:
hr_api_company:
resource: "#HRAPIBundle/Resources/config/routing/company.yml"
prefix: /company
And in file: HardCoreMore/HRAPIBundle/Resources/config/routing/company.yml
I have defined route for creating company like this:
hardcoremore_hr_api_company_create:
pattern: /
defaults: { _controller: HRAPIBundle:Company:create }
methods: [POST]
Now the route is matched with following url:
POST company/
but it is not matched when I called it with:
POST company
How can I define route without ending slash when importing route and prefixing it?
this is not possible, see : https://github.com/symfony/symfony/issues/4322
I hope this has helped

Symfony2 route based on host. With parameters

I have followed the instructions here:
http://symfony.com/doc/current/components/routing/hostname_pattern.html
To make the route based on the host. However I want to use parameters instead of hard coding. The documentation says you can use service parameters, but I seem to be having trouble getting the parameters to work.
Here is the code from routing.yml:
rc_course_new:
pattern: /course/new
host: "{ domain }"
defaults: { _controller: CoursesRCWizardBundle:Wizard:new }
requirements:
domain: "%rc_domain%"
And here is the code from services.yml:
parameters:
rc_domain: my.domain.com
I get this error (looks like it is not picking up the parameter but seeing it as a hard code):
Oops! Google Chrome could not find { domain }
Managed to fix this:
In the routing:
rc_course_new:
pattern: /course/new
host: "%rc_domain%"
defaults: { _controller: CoursesRCWizardBundle:Wizard:new }
In the services (might work better in the parameters file) file:
parameters:
rc_domain: my.domain.com

Symfony2 - No route found for "GET /Categoria/"

Symfony2 returns No route found for "GET /Categoria/" when I try to access to localhost/Symfony/web/app_dev.php/Categoria/, the page localhost/Symfony/web/app_dev.php/hello/Guido works.
src\grupo85\entregaFinalBundle\Resources\config\routing.yml:
grupo85entrega_final_homepage:
pattern: /hello/{name}
defaults: { _controller: grupo85entregaFinalBundle:Default:index }
app\config\routing.yml:
grupo85entrega_final:
resource: "#grupo85entregaFinalBundle/Resources/config/routing.yml"
prefix: /
grupo85entregaFinalBundle:
resource: "#grupo85entregaFinalBundle/Controller/"
type: annotation
prefix: /
php app/console route:debug
categoria GET ANY ANY /categoria/
categoria_create POST ANY ANY /categoria/
categoria_new GET ANY ANY /categoria/new
categoria_show GET ANY ANY /categoria/{id}
categoria_edit GET ANY ANY /categoria/{id}/edit
categoria_update PUT ANY ANY /categoria/{id}
categoria_delete DELETE ANY ANY /categoria/{id}
I've also tried to run the cache:clear --env prod command and remove pp/cache folder manually.
What's wrong?
Thanks.
Please understand error message. You have not route for /Categoria/. You have route for /categoria/. Please notice lower case. SF2 router recognizes lower and upper cases.

Resources