Well, having the following in my routing_dev.yml
_welcome:
pattern: /
defaults: { _controller: AcmeDemoBundle:Welcome:index }
homepage:
pattern: /
defaults: { _controller: AcmeDemoBundle:Ideup:index }
aboutme:
pattern: /aboutme
defaults: { _controller: AcmeDemoBundle:Ideup:about }
_ideup:
resource: "#AcmeDemoBundle/Controller/IdeupController.php"
type: annotation
prefix: /ideup
_form:
resource: "#AcmeDemoBundle/Controller/FormController.php"
type: annotation
_wdt:
resource: "#WebProfilerBundle/Resources/config/routing/wdt.xml"
prefix: /_wdt
_profiler:
resource: "#WebProfilerBundle/Resources/config/routing/profiler.xml"
prefix: /_profiler
_main:
resource: routing.yml
I'm trying to have a simple form:
<form action="{{ path('_form') }}" method="POST" id="contact_form">
But I keep getting this following exception: "Route "_form" does not exist."
I just don't know where else to look and what to do, any ideas?
_form:
resource: "#AcmeDemoBundle/Controller/FormController.php"
type: annotation
This will just load annotated routes from the FormController.
For example:
/**
* #Route("/my/route", name="my_route")
*/
public function myRouteAction() { ... }
If you want a _form route, you should either load all annotationed routes from the FormController or define it in another way:
_form:
pattern: /path/to/your/form
defaults: { _controller: AcmeDemoBundle:Form:myFormAction }
Of course myFormAction() should exist in the FormController.
Related
I have URL error:
link rel="alternate" type="application/atom+xml" title="Latest Jobs"
href="{{ url('job', {'_format': 'atom'}) }}" />
Routing.yml file:
job_job:
resource: "#JobBundle/Resources/config/routing/job.yml"
prefix: /job
job_homepage:
path: /
defaults: { _controller: JobBundle:Default:index }
This what my job.yml contains -
(I use in path "job_homepage" , in url I use "job" , but when I'm trying to run show action or edit action it work correctly)
job_index:
path: /
defaults: { _controller: "JobBundle:Job:index" }
methods: GET
job_show:
path: /{id}/show
defaults: { _controller: "JobBundle:Job:show" }
methods: GET
job_new:
path: /new
defaults: { _controller: "JobBundle:Job:new" }
methods: [GET, POST]
job_edit:
path: /{id}/edit
defaults: { _controller: "JobBundle:Job:edit" }
methods: [GET, POST]
job_delete:
path: /{id}/delete
defaults: { _controller: "JobBundle:Job:delete" }
methods: DELETE
I use http://127.0.0.1:8000/job/ to run my project
You dont have a route for job in your routing file.
Should be something like:
link rel="alternate" type="application/atom+xml" title="Latest Jobs" href="{{ url('job_homepage', {'_format': 'atom'}) }}" />
Or if you have different named routes in "#JobBundle/Resources/config/routing/job.yml" use one of those. But the error is pretty clear, you dont have a route named job
I Use Symfony 3, And I Want to understand How symfony chouses the Route.
I have 3 routes, 2 in routing.yml and 1 in annotation.
this is my code:
app/config/routing.yml
app:
resource: "#AppBundle/Controller/"
type: annotation
hello:
path: "hello/{firstName}"
defaults: {_controller: AppBundle:Default:rotta,firstName: "route1"}
hello_name:
path: "hello/{firstName}"
defaults: {_controller: AppBundle:Default:rotta, firstName: "route2"}
src/AppBundle/Controller/DefaultController.php
/**
* #Route("hello/{firstName}", name="hello", defaults={"firstName" = "Annotation"})
*/
public function rottaAction($firstName,Request $request)
{
var_dump($request->get('firstName'));
exit;
}
My result is
string 'route1' (length=6)
with this routing.yml
hello:
path: "hello/{firstName}"
defaults: {_controller: AppBundle:Default:rotta,firstName: "route1"}
hello_name:
path: "hello/{firstName}"
defaults: {_controller: AppBundle:Default:rotta, firstName: "route2"}
app:
resource: "#AppBundle/Controller/"
type: annotation
My result is
string 'route2' (length=6)
and with this combination:
hello:
path: "hello/{firstName}"
defaults: {_controller: AppBundle:Default:rotta,firstName: "route1"}
hello_name:
path: "hello/{firstName}"
defaults: {_controller: AppBundle:Default:rotta, firstName: "route2"}
#app:
# resource: "#AppBundle/Controller/"
# type: annotation
my result is:
string 'route1' (length=6)
FileLoaderImportCircularReferenceException: Circular reference
detected in "/app/config/routing_dev.yml"
("/app/config/routing_dev.yml" >
"/app/config/routing.yml" > "." >
"#GabrielAdminPanelBundle/Controller/" >
"/app/config/routing_dev.yml").
I'm trying to achieve this:
http://symfony.com/doc/current/cookbook/routing/custom_route_loader.html#more-advanced-loaders
so I created this file
AdvancedLoader.php
<?php
//namespace Acme\DemoBundle\Routing;
namespace Gabriel\AdminPanelBundle\Routing;
use Symfony\Component\Config\Loader\Loader;
use Symfony\Component\Routing\RouteCollection;
class AdvancedLoader extends Loader
{
public function load($resource, $type = null)
{
$collection = new RouteCollection();
$resource = '#GabrielAdminPanelBundle/Resources/config/routing.yml';
$type = 'yaml';
$importedRoutes = $this->import($resource, $type);
$collection->addCollection($importedRoutes);
return $collection;
}
public function supports($resource, $type = null)
{
return $type === 'advanced_extra';
}
}
/src/Gabriel/AdminPanelBundle/Resources/config/services.yml
services:
gabriel.routing_loader:
class: Gabriel\AdminPanelBundle\Routing\AdvancedLoader
tags:
- { name: routing.loader }
/app/config/routing.yml
gabriel_messaging:
resource: "#GabrielMessagingBundle/Controller/"
type: annotation
prefix: /
fos_js_routing:
resource: "#FOSJsRoutingBundle/Resources/config/routing/routing.xml"
# app/config/routing.yml
Gabriel_Extra:
resource: .
type: advanced_extra
app/config/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
/src/Gabriel/AdminPanelBundle/Resources/config/routing.yml
gabriel_admin_panel:
resource: "#GabrielAdminPanelBundle/Controller/"
type: advanced_extra
prefix: /superuser
Take a close look at #GabrielAdminPanelBundle/Resources/config/routing.yml:
gabriel_admin_panel:
resource: "#GabrielAdminPanelBundle/Controller/"
type: advanced_extra
prefix: /superuser
The type specifies which loader should be used, in this case you said advanced_extra, which is your loader. Your loader includes this file again and the file will execute the loader again, this will continue forever (in other words: a circular reference).
Please also note that you already included the routes in app/config/routing.yml:
gabriel_messaging:
resource: "#GabrielMessagingBundle/Controller/"
type: annotation
prefix: /
This time, you use the correct type: annotation. You should remove this entry and edit the #GabrielAdminPanelBundle/Resources/config/routing.yml file to use correct types.
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.
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