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









share|improve this question























  • 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















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









share|improve this question























  • 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













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









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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.*, share app/config/routing.yml and on Symfony 4.*, share config/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











  • On Symfony 3.*, share app/config/routing.yml and on Symfony 4.*, share config/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













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.






share|improve this answer




















  • 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










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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

























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.






share|improve this answer




















  • 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














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.






share|improve this answer




















  • 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












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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










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
















  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto