Symfony2 routing pattern route not found - php

i have a very simple understanding question
isnt it possible to have such routing patterns ?
foobar_foobar_videos_all:
pattern: /video
defaults: { _controller: foobarfoobarBundle:Content:showVideos }
foobar_foobar_videos_by_category:
pattern: /video/{category}
defaults: { _controller: foobarfoobarBundle:Content:showVideosByCategory }
foobar_foobar_videos_by_category_and_offset:
pattern: /video/{category}/page/{offset}
defaults: { _controller: foobarfoobarBundle:Content:showVideosByCategory }
this way the first route doesnt work, printing
"No route found for "GET /video"
while the others work perfect.
How can i route to /video ?

The solution was to put it the /video pattern to the end
foobar_foobar_videos_by_category:
pattern: /video/{category}
defaults: { _controller: foobarfoobarBundle:Content:showVideosByCategory }
foobar_foobar_videos_by_category_and_offset:
pattern: /video/{category}/page/{offset}
defaults: { _controller: foobarfoobarBundle:Content:showVideosByCategory }
foobar_foobar_videos_all:
pattern: /video
defaults: { _controller: foobarfoobarBundle:Content:showVideos }

Related

Unable to generate Url for the name 'index' in Symfony?

I am having a little routing problem, here is my code in my controller :
...
else {
return $this->redirectToRoute('index');
}
...
And here is the message I am having :
Unable to generate a URL for the named route "index" as such route does not exist.
And My routing file is :
front_signup:
path: /signup
defaults: { _controller: FrontBundle:signup:inscription }
front_index:
path: /index
defaults: { _controller: FrontBundle:index:acceuil }
front_login:
path: /login
defaults: { _controller: FrontBundle:login:connection }
Thanks for any help.

symfony2 routing, bad parsing

I have an application in symfony2, and i create routing like this:
spec_add:
path: /add.html
defaults: { _controller: MyBundle:Spec:add }
methods: [GET, POST]
spec_add_to_order:
path: /{indent}/add.html
defaults: { _controller: MyBundle:Spec:add }
methods: [GET, POST]
requirements:
indent: \d+
spec_edit:
path: /{id}/edit.html
defaults: { _controller: MyBundle:Spec:add }
methods: [GET, POST]
requirements:
id: \d+
And I have controller SpecController and method:
public function addAction(Indent $indent = null,Specification $specification = null, Request $request)
when I go to address mydomain.dev/{myindentId}/add.html
i get indent object but I get Specification object too, Why? i don't want specification in this case what am I doing wrong?

symfony route gives no response

as said, my problem is I get an empty response (looked in firebug) when calling a route on a post method. placing a "die('something')" shows me the action isn't called... I have no idea where the request is handled....
An important thing could be I renamed an entity and all that was related (controllers, forms ...) it works fine except when trying to call Contact -> createAction via my route :
contact_create:
path: /create
defaults: { _controller: "MainMainBundle:Contact:create" }
requirements: { _method: post|put }
I receive empty response.. even if i call it via get method, no error, empty response...
action in controller :
public function createAction(Request $request) { ...
I really dont know if there's something obvious in front of me, and I dont see it, or could it be a kind of routing cache, messing up with the renaming of the routes, controllers, entity...
If anyone has an idea, i'd be very thankul !
regards
EDIT:
contact.yml :
contact:
path: /{companyId}
defaults: { _controller: "MainMainBundle:Contact:index" }
contact_show:
path: /{id}/show
defaults: { _controller: "MainMainBundle:Contact:show" }
contact_new:
path: /new/{companyId}
defaults: { _controller: "MainMainBundle:Contact:new" }
contact_create:
path: /create
defaults: { _controller: "MainMainBundle:Contact:create" }
requirements: { _method: post|put }
contact_edit:
path: /{id}/edit
defaults: { _controller: "MainMainBundle:Contact:edit" }
contact_update:
path: /{id}/update
defaults: { _controller: "MainMainBundle:Contact:update" }
requirements: { _method: post|put }
contact_delete:
path: /{id}/delete
defaults: { _controller: "MainMainBundle:Contact:delete" }
requirements: { _method: post}
contact_revive:
path: /{id}/revive
defaults: { _controller: "MainMainBundle:Contact:revive" }
requirements: { _method: post}
$ php app/console router:debug | grep contact
deal_ajax_load_new_form ANY ANY ANY /deal/dealajaxloadnewform/{contactId}
contact ANY ANY ANY /contact/{companyId}
contact_show ANY ANY ANY /contact/{id}/show
contact_new ANY ANY ANY /contact/new/{companyId}
contact_create POST|PUT ANY ANY /contact/create
contact_edit ANY ANY ANY /contact/{id}/edit
contact_update POST|PUT ANY ANY /contact/{id}/update
contact_delete POST ANY ANY /contact/{id}/delete
contact_revive POST ANY ANY /contact/{id}/revive
Try placing 'contact_create' route on top of contact.yml, I suppose that first route on that file 'contact' is matching with "/create" path (companyId = create) and executing "MainMainBundle:Contact:index" controller instead of "MainMainBundle:Contact:create" one.
Are you using jsrouting-bundle (friendsofsymfony) ? If so, try running the following command
app/console fos:js-routing:dump
Check if you use correct port. In my case port was 8080 but I was using 8000

Symfony 2 routing doesnt work in prod

im developed a pretty simple blog in symfony.
There are 2 bundles: blog and admin which are both fine in dev enviroment.. however the main admin route doesnt seem to work in prod as it throws a 404. Every other route (e.g. /admin/categories and so on) works but /admin works only if i write /app_dev.php/admin. Already cleared the cache.
I dont think that i inserted some code to block admin cos i dont know where could i do such things..
Also dont know exactly what code snippets need for debugging sorry but i will update if anybody ask for one.
Admin route:
admin_image_upload:
path: /imageupload
defaults: { _controller: SzoBeszAdminBundle:Admin:imageUpload }
admin_posts:
path: /admin
defaults: { _controller: SzoBeszAdminBundle:Admin:index }
admin_posts_paginated:
path: /admin/posts/{pageNumber}
defaults: { _controller: SzoBeszAdminBundle:Admin:index }
admin_categories:
path: /admin/categories
defaults: { _controller: SzoBeszAdminBundle:Admin:category }
admin_category_submit:
path: /admin/categorysubmit
defaults: { _controller: SzoBeszAdminBundle:Admin:categorySubmit }
admin_post_submit:
path: /admin/postsubmit
defaults: { _controller: SzoBeszAdminBundle:Admin:postSubmit }
requirements:
_method: GET|POST
admin_post_edit:
path: /admin/post/edit/{id}
defaults: { _controller: SzoBeszAdminBundle:Admin:postEdit }
requirements:
id: \d+
admin_post_delete:
path: /admin/post/delete/{id}
defaults: { _controller: SzoBeszAdminBundle:Admin:postDelete }
requirements:
id: \d+
admin_category_edit:
path: /admin/category/edit/{id}
defaults: { _controller: SzoBeszAdminBundle:Admin:categoryEdit }
requirements:
id: \d+
admin_category_delete:
path: /admin/category/delete/{id}
defaults: { _controller: SzoBeszAdminBundle:Admin:categoryDelete }
requirements:
id: \d+
Blog route:
blog_homepage:
path: /
defaults: { _controller: BlogBundle:Main:index }
requirements:
_method: GET
blog_homepaginated:
path: /page/{pageNumber}
defaults: { _controller: BlogBundle:Main:index }
blog_categorypage:
path: /{theCategory}
defaults: { _controller: BlogBundle:Main:showCategory }
requirements:
_method: GET
blog_categorypaginated:
path: /{theCategory}/page/{pageNumber}
defaults: { _controller: BlogBundle:Main:showCategory }
requirements:
_method: GET
blog_tagpage:
path: /tag/{tag}
defaults: { _controller: BlogBundle:Main:tag }
blog_showpost:
path: /{theCategory}/{title}
defaults: { _controller: BlogBundle:Main:showPost }
requirements:
_method: GET
blog_tagpaginated:
path: /tag/{tag}/page/{pageNumber}
defaults: { _controller: BlogBundle:Main:tag }
Security:
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
in_memory:
memory:
users:
szobeszadmin: { password: ***, roles: [ 'ROLE_SUPER_ADMIN' ] }
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
admin_secured:
pattern: ^/
anonymous: ~
http_basic:
realm: "Secured Area"
access_control:
- { path: ^/admin, roles: ROLE_SUPER_ADMIN }
Make sure you register ALL YOUR CREATED BUNDLES in Kernel are here, it is a prod section:
$bundles = array(...);
Leave registered dev bundles like this:
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
Also if in app.php file you see false (parameter is for testing):
$kernel = new AppKernel('prod', false);
Change false to true:
$kernel = new AppKernel('prod', true);
Hope it helped, have a nice day.
Make sure you have the mod_rewrite module enabled in Apache.
See here for some help.
The problem was that i created an admin folder inside the web folder so apache tried the /admin route with that folder instead of the route i set.

Why is symfony2 functional test client->request() not getting successful response()?

So I've decided to delve into phpunit testing and I've shamefully written out my php code before writing my test. Anyway, I'm just writing a very simple test that tells me if I actually found the correct web page. Unfortunately my one assertion test keeps failing. I know my route "/login" is correct because when I navigate to localhost/index.php/login (where index.php is a link to app_dev.php), the page comes up correctly. Bellow is my routing.php file:
caremonk_mainsite_login:
pattern: /login
defaults: { _controller: CaremonkMainSiteBundle:Security:login }
requirements:
_method: POST|GET
caremonk_mainsite_login_check:
pattern: /login_check
requirements:
_method: POST|GET
caremonk_mainsite_signup:
pattern: /signup
defaults: { _controller: CaremonkMainSiteBundle:CreateUser:signup }
requirements:
_method: POST|GET
caremonk_mainsite_logout:
pattern: /logout
defaults: { _controller: CaremonkMainSiteBundle:Security:logout}
requirements:
_method: POST|GET
caremonk_mainsite_post_blog:
pattern: /post_blog
defaults: { _controller: CaremonkMainSiteBundle:UserEvents:post }
requirements:
_method: POST|GET
caremonk_mainsite_my_profile:
pattern: /my_profile_edit
defaults: { _controller: CaremonkMainSiteBundle:UserEvents:editProfile }
requirements:
_method: POST|GET
caremonk_mainsite_activate:
pattern: /activate/{username}/{token}
defaults: { _controller: CaremonkMainSiteBundle:CreateUser:activateAccount }
requirements:
_methods: GET
caremonk_mainsite_password_reset_request:
pattern: /reset_password/
defaults: { _controller: CaremonkMainSiteBundle:Security:passwordResetRequest }
requirements:
_methods: GET | POST
caremonk_mainsite_reset_password_email:
pattern: /reset_password_email/{username}/{resetPasswordToken}
defaults: { _controller: CaremonkMainSiteBundle:Security:sendNewPassword }
requirements:
_methods: GET
caremonk_mainsite_change_password:
pattern: /change_password
defaults: { _controller: CaremonkMainSiteBundle:Security:changePassword }
requirements:
_methods: GET | POST
caremonk_mainsite_home:
pattern: /
defaults: { _controller: CaremonkMainSiteBundle:Home:index }
requirements:
_methods: GET
Anyway bellow is the test code that keeps failing:
<?php
namespace Caremonk\MainSiteBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class SecurityControllerFunctionalTest extends WebTestCase
{
public function testIndex()
{
$client = static::createClient();
// I've done many tests
// I've tried the following request with all failed results
// $crawler = $client->request('GET', 'index.php/login');
// $crawler = $client->request('GET', 'http://localhost/indpex.php/login');
// $crawler = $client->request('GET', 'localhost/index.php/login');
// You get the idea
$crawler = $client->request('GET', '/login');
$this->assertTrue($client->getResponse()->isSuccessful());
}
}
My routing.yml and routing_dev.yml files are shown bellow
#routing_dev.yml
_wdt:
resource: "#WebProfilerBundle/Resources/config/routing/wdt.xml"
prefix: /_wdt
_profiler:
resource: "#WebProfilerBundle/Resources/config/routing/profiler.xml"
prefix: /_profiler
_configurator:
resource: "#SensioDistributionBundle/Resources/config/routing/webconfigurator.xml"
prefix: /_configurator
_main:
resource: routing.yml
#routing.yml
caremonk_main_site:
resource: "#CaremonkMainSiteBundle/Resources/config/routing.yml"
prefix: /
You prefixed your imported routes with a "/", and your routes path start with a "/".
Normally I would prefix my routes with something more meaningful (and does not end with a "/") or remove the "/" from your imported routes.
Running the following command should give you insight to how your routes are registered.
app/console debug:router

Categories