2

i create a controller pageController.php :

<?php 

namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;

class pageController {

    public function index()
    {
        return new Response('<html><body>hello...</body></html>');
    }
    public function contactAction()
    {
        return new Response('<html><body>contact...</body></html>');
    }

}

and here is the routes.yml

index:
    path: /
    controller: App\Controller\pageController::index

contact:
    path: /contact
    controller: App\Controller\pageController::contactAction

the index works fine, but the contact doesn't work!

Note: when I changed the path of index from "/" to "/index", it doesn't work anymore, it shows 404 not found

I don't want to use annotations until i want to fix this

0

2 Answers 2

1
contact:
    path: /contact
    controller: App\Controller\pageController::contact

Symfony will look for your contactAction you don't need to mention it in your YML

Ps: you don't call a route by a route name /index wont work but you call it by the path /

Sign up to request clarification or add additional context in comments.

1 Comment

I call it by the path ! which is '/contact' but 404 not found problem appear
0

I don't know which version of symfony you are using, but if it is symfony 2.x then you should name your index method as indexAction (exactly like you have in contact).

routes.yml:

index:
path: /
controller: App\Controller\pageController::indexAction

controller:

public function indexAction()
{
     return new Response('<html><body>hello...</body></html>');
}

You should also make sure that your routes.yml are properly loaded.

1 Comment

but the index works fine . if i change the path of index from ' / ' to ' /page' or any other path ,and i type /page , i get 404 not found prob! i am using symfony 5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.