I am new with Symfony 2.. I try something really basic.. I have just created a bundle with the command line et put this in my controller :
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\BrowserKit\Response;
class DefaultController extends Controller
{
public function indexAction($name)
{
return new Response('<html><body>Hello '.$name.'!</body></html>');
}
}
and I have a logicException with "the controler must return a response"
this is not what I am doing here ?
Thank u
PS : I add the routing.yml in app
acme_hello:
resource: "@AcmeHelloBundle/Resources/config/routing.yml"
prefix: /
routing.yml in Resources
acme_hello_homepage:
pattern: /hello/{name}
defaults: { _controller: AcmeHelloBundle:Default:index }
The response could be an HTML page, JSON, XML, a file download, a redirect, a 404 error or anything else. The controller runs whatever arbitrary logic your application needs to render the content of a page.
In Symfony, a controller is usually a class method which is used to accept requests, and return a Response object. When mapped with a URL, a controller becomes accessible and its response can be viewed.
It worked without it on one server, but not another Symfony2 expects a Response object to be returned from a controller action. I'm guessing you probably want something like the following:
You can also return a new Response object directly, eg return new Response ('Hello, world') if needed. See the documentation for more details. That works, I generated the entity and crud with the console and on CentOS is not working correcly with annotations.
The controller must return a Symfony\Component\HttpFoundation\Response
instance, so you should have:
use Symfony\Component\HttpFoundation\Response;
instead of
use Symfony\Component\BrowserKit\Response;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With