Symfony throws “no Response returned” Error even though I return Response
up vote
0
down vote
favorite
1) There is this Controller Function I made:
/**
* @Route("/add", name="add" )
*/
public function add_question()
return $this->render("add.html.twig",);
2) When I go to http://127.0.0.1:8000/add Symfony returns this error:
The controller must return a response (null given). Did you forget to add a
return statement somewhere in your controller?
3) I have bunch of other Controllers that have the same structure and work correctly.
4) Whenever I want to add a new Controller, this error is being thrown.
5) I tried to return Response object - it doesn't work either.
EDIT:
my config/routes/annotations.yaml file:
controllers:
resource: ../../src/Controller/
type: annotation
php symfony
add a comment |
up vote
0
down vote
favorite
1) There is this Controller Function I made:
/**
* @Route("/add", name="add" )
*/
public function add_question()
return $this->render("add.html.twig",);
2) When I go to http://127.0.0.1:8000/add Symfony returns this error:
The controller must return a response (null given). Did you forget to add a
return statement somewhere in your controller?
3) I have bunch of other Controllers that have the same structure and work correctly.
4) Whenever I want to add a new Controller, this error is being thrown.
5) I tried to return Response object - it doesn't work either.
EDIT:
my config/routes/annotations.yaml file:
controllers:
resource: ../../src/Controller/
type: annotation
php symfony
Have you checked if the path "/add" is not duplicated for another router? you can see the list of routers by this command : php bin/console debug:router. You can also var_dump the response just before returning it to see if it is not null
– Cheikh HAIBALA
Nov 10 at 23:25
On Symfony 3.*, shareapp/config/routing.yml
and on Symfony 4.*, shareconfig/routes/annotations.yaml
– Trix
Nov 11 at 4:17
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
1) There is this Controller Function I made:
/**
* @Route("/add", name="add" )
*/
public function add_question()
return $this->render("add.html.twig",);
2) When I go to http://127.0.0.1:8000/add Symfony returns this error:
The controller must return a response (null given). Did you forget to add a
return statement somewhere in your controller?
3) I have bunch of other Controllers that have the same structure and work correctly.
4) Whenever I want to add a new Controller, this error is being thrown.
5) I tried to return Response object - it doesn't work either.
EDIT:
my config/routes/annotations.yaml file:
controllers:
resource: ../../src/Controller/
type: annotation
php symfony
1) There is this Controller Function I made:
/**
* @Route("/add", name="add" )
*/
public function add_question()
return $this->render("add.html.twig",);
2) When I go to http://127.0.0.1:8000/add Symfony returns this error:
The controller must return a response (null given). Did you forget to add a
return statement somewhere in your controller?
3) I have bunch of other Controllers that have the same structure and work correctly.
4) Whenever I want to add a new Controller, this error is being thrown.
5) I tried to return Response object - it doesn't work either.
EDIT:
my config/routes/annotations.yaml file:
controllers:
resource: ../../src/Controller/
type: annotation
php symfony
php symfony
edited Nov 11 at 9:59
asked Nov 10 at 22:03
Maciek
43
43
Have you checked if the path "/add" is not duplicated for another router? you can see the list of routers by this command : php bin/console debug:router. You can also var_dump the response just before returning it to see if it is not null
– Cheikh HAIBALA
Nov 10 at 23:25
On Symfony 3.*, shareapp/config/routing.yml
and on Symfony 4.*, shareconfig/routes/annotations.yaml
– Trix
Nov 11 at 4:17
add a comment |
Have you checked if the path "/add" is not duplicated for another router? you can see the list of routers by this command : php bin/console debug:router. You can also var_dump the response just before returning it to see if it is not null
– Cheikh HAIBALA
Nov 10 at 23:25
On Symfony 3.*, shareapp/config/routing.yml
and on Symfony 4.*, shareconfig/routes/annotations.yaml
– Trix
Nov 11 at 4:17
Have you checked if the path "/add" is not duplicated for another router? you can see the list of routers by this command : php bin/console debug:router. You can also var_dump the response just before returning it to see if it is not null
– Cheikh HAIBALA
Nov 10 at 23:25
Have you checked if the path "/add" is not duplicated for another router? you can see the list of routers by this command : php bin/console debug:router. You can also var_dump the response just before returning it to see if it is not null
– Cheikh HAIBALA
Nov 10 at 23:25
On Symfony 3.*, share
app/config/routing.yml
and on Symfony 4.*, share config/routes/annotations.yaml
– Trix
Nov 11 at 4:17
On Symfony 3.*, share
app/config/routing.yml
and on Symfony 4.*, share config/routes/annotations.yaml
– Trix
Nov 11 at 4:17
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Okay, I found the solution.
I have a few Controllers in my project.
One of them was located almost on top of the file and had following routing:
/**
* @Route("/question_id", name="questions" ) <--QUESTION ROUTE
*/
the logic of controller was like that:
function GenerateQuestionPage($question_id)
1find question in my database whose $id is equal to question_id.
2a. If you find such question then render proper twig template.
2b. If You don't find such question then you echo "No such question found";
Whenever I wanted to go to some page whose Routing was defined below the definition of the GenerateQuestionPage Controller, Symfony thought I was trying to use Question Route with
nonnumerical question_id. Then it was searching for such question in DB but obviously couldn't find so it wasn't returning Response object.
My solution was to relocate GenerateQuestionPage controller to the bottom of the file.
If your IDs do only contain digits, you can add a requirement to let it match only some paths like this:@Route("/question_id", name="questions", requirements="question_id": "d+")
(see also symfony.com/doc/current/…)
– xabbuh
Nov 12 at 9:36
Wow, that's a great solution. Thanks!
– Maciek
Nov 12 at 13:08
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Okay, I found the solution.
I have a few Controllers in my project.
One of them was located almost on top of the file and had following routing:
/**
* @Route("/question_id", name="questions" ) <--QUESTION ROUTE
*/
the logic of controller was like that:
function GenerateQuestionPage($question_id)
1find question in my database whose $id is equal to question_id.
2a. If you find such question then render proper twig template.
2b. If You don't find such question then you echo "No such question found";
Whenever I wanted to go to some page whose Routing was defined below the definition of the GenerateQuestionPage Controller, Symfony thought I was trying to use Question Route with
nonnumerical question_id. Then it was searching for such question in DB but obviously couldn't find so it wasn't returning Response object.
My solution was to relocate GenerateQuestionPage controller to the bottom of the file.
If your IDs do only contain digits, you can add a requirement to let it match only some paths like this:@Route("/question_id", name="questions", requirements="question_id": "d+")
(see also symfony.com/doc/current/…)
– xabbuh
Nov 12 at 9:36
Wow, that's a great solution. Thanks!
– Maciek
Nov 12 at 13:08
add a comment |
up vote
0
down vote
accepted
Okay, I found the solution.
I have a few Controllers in my project.
One of them was located almost on top of the file and had following routing:
/**
* @Route("/question_id", name="questions" ) <--QUESTION ROUTE
*/
the logic of controller was like that:
function GenerateQuestionPage($question_id)
1find question in my database whose $id is equal to question_id.
2a. If you find such question then render proper twig template.
2b. If You don't find such question then you echo "No such question found";
Whenever I wanted to go to some page whose Routing was defined below the definition of the GenerateQuestionPage Controller, Symfony thought I was trying to use Question Route with
nonnumerical question_id. Then it was searching for such question in DB but obviously couldn't find so it wasn't returning Response object.
My solution was to relocate GenerateQuestionPage controller to the bottom of the file.
If your IDs do only contain digits, you can add a requirement to let it match only some paths like this:@Route("/question_id", name="questions", requirements="question_id": "d+")
(see also symfony.com/doc/current/…)
– xabbuh
Nov 12 at 9:36
Wow, that's a great solution. Thanks!
– Maciek
Nov 12 at 13:08
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Okay, I found the solution.
I have a few Controllers in my project.
One of them was located almost on top of the file and had following routing:
/**
* @Route("/question_id", name="questions" ) <--QUESTION ROUTE
*/
the logic of controller was like that:
function GenerateQuestionPage($question_id)
1find question in my database whose $id is equal to question_id.
2a. If you find such question then render proper twig template.
2b. If You don't find such question then you echo "No such question found";
Whenever I wanted to go to some page whose Routing was defined below the definition of the GenerateQuestionPage Controller, Symfony thought I was trying to use Question Route with
nonnumerical question_id. Then it was searching for such question in DB but obviously couldn't find so it wasn't returning Response object.
My solution was to relocate GenerateQuestionPage controller to the bottom of the file.
Okay, I found the solution.
I have a few Controllers in my project.
One of them was located almost on top of the file and had following routing:
/**
* @Route("/question_id", name="questions" ) <--QUESTION ROUTE
*/
the logic of controller was like that:
function GenerateQuestionPage($question_id)
1find question in my database whose $id is equal to question_id.
2a. If you find such question then render proper twig template.
2b. If You don't find such question then you echo "No such question found";
Whenever I wanted to go to some page whose Routing was defined below the definition of the GenerateQuestionPage Controller, Symfony thought I was trying to use Question Route with
nonnumerical question_id. Then it was searching for such question in DB but obviously couldn't find so it wasn't returning Response object.
My solution was to relocate GenerateQuestionPage controller to the bottom of the file.
answered Nov 11 at 10:20
Maciek
43
43
If your IDs do only contain digits, you can add a requirement to let it match only some paths like this:@Route("/question_id", name="questions", requirements="question_id": "d+")
(see also symfony.com/doc/current/…)
– xabbuh
Nov 12 at 9:36
Wow, that's a great solution. Thanks!
– Maciek
Nov 12 at 13:08
add a comment |
If your IDs do only contain digits, you can add a requirement to let it match only some paths like this:@Route("/question_id", name="questions", requirements="question_id": "d+")
(see also symfony.com/doc/current/…)
– xabbuh
Nov 12 at 9:36
Wow, that's a great solution. Thanks!
– Maciek
Nov 12 at 13:08
If your IDs do only contain digits, you can add a requirement to let it match only some paths like this:
@Route("/question_id", name="questions", requirements="question_id": "d+")
(see also symfony.com/doc/current/…)– xabbuh
Nov 12 at 9:36
If your IDs do only contain digits, you can add a requirement to let it match only some paths like this:
@Route("/question_id", name="questions", requirements="question_id": "d+")
(see also symfony.com/doc/current/…)– xabbuh
Nov 12 at 9:36
Wow, that's a great solution. Thanks!
– Maciek
Nov 12 at 13:08
Wow, that's a great solution. Thanks!
– Maciek
Nov 12 at 13:08
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243871%2fsymfony-throws-no-response-returned-error-even-though-i-return-response%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you checked if the path "/add" is not duplicated for another router? you can see the list of routers by this command : php bin/console debug:router. You can also var_dump the response just before returning it to see if it is not null
– Cheikh HAIBALA
Nov 10 at 23:25
On Symfony 3.*, share
app/config/routing.yml
and on Symfony 4.*, shareconfig/routes/annotations.yaml
– Trix
Nov 11 at 4:17