Navigation Menu

Skip to content

Commit

Permalink
[FrameworkBundle] fixed built-in controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Aug 14, 2010
1 parent 96e9a68 commit 714fa6f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 16 deletions.
Expand Up @@ -3,6 +3,7 @@
namespace Symfony\Bundle\FrameworkBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller;
use Symfony\Components\HttpFoundation\Response;

/*
* This file is part of the Symfony framework.
Expand All @@ -20,8 +21,13 @@
*/
class DefaultController extends Controller
{
/**
* Renders the Symfony2 welcome page.
*
* @return Response A Response instance
*/
public function indexAction()
{
return $this->render('FrameworkBundle:Default:index');
return $this['templating']->renderResponse('FrameworkBundle:Default:index');
}
}
Expand Up @@ -25,21 +25,26 @@
class ExceptionController extends Controller
{
/**
* Converts an Exception to a Response.
*
* @param \Exception $exception An Exception instance
* @param Request $request The original Request instance
* @param array $logs An array of logs
*
* @throws \InvalidArgumentException When the exception template does not exist
*/
public function exceptionAction(\Exception $exception, Request $originalRequest, array $logs)
{
$template = $this->container->getParameter('kernel.debug') ? 'exception' : 'error';

$request = $this->getRequest();
$format = $format = $originalRequest->getRequestFormat();

// when using CLI, we force the format to be TXT
if (0 === strncasecmp(PHP_SAPI, 'cli', 3)) {
$format = 'txt';
}

$template = $this->container->getTemplatingService()->getLoader()->load($template, array(
$template = $this['templating']->getLoader()->load($template, array(
'bundle' => 'FrameworkBundle',
'controller' => 'Exception',
'format' => '.'.$format,
Expand Down Expand Up @@ -73,7 +78,7 @@ public function exceptionAction(\Exception $exception, Request $originalRequest,
require $template;
$content = ob_get_clean();

$response = $this->container->getResponseService();
$response = $this['response'];
$response->setStatusCode($code);
$response->setContent($content);

Expand Down
Expand Up @@ -3,6 +3,7 @@
namespace Symfony\Bundle\FrameworkBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller;
use Symfony\Components\HttpFoundation\Response;

/*
* This file is part of the Symfony framework.
Expand All @@ -20,16 +21,25 @@
*/
class InternalController extends Controller
{
public function indexAction()
/**
* Forwards to the given controller with the given path.
*
* @param string $path The path
* @param string $controller The controller name
*
* @return Response A Response instance
*/
public function indexAction($path, $controller)
{
$request = $this->getRequest();
$request = $this['request'];
$attributes = $request->attributes;

if ('none' !== $request->attributes->get('path'))
if ('none' !== $path)
{
parse_str($request->attributes->get('path'), $tmp);
$request->attributes->add($tmp);
parse_str($path, $tmp);
$attributes->add($tmp);
}

return $this->forward($request->attributes->get('controller'), $request->attributes->all(), $request->query->all());
return $this['controller_resolver']->forward($controller, $attributes->all(), $request->query->all());
}
}
Expand Up @@ -3,6 +3,7 @@
namespace Symfony\Bundle\FrameworkBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller;
use Symfony\Components\HttpFoundation\Response;

/*
* This file is part of the Symfony framework.
Expand All @@ -20,29 +21,37 @@
*/
class RedirectController extends Controller
{
/*
/**
* Redirects to another route.
*
* It expects a route path parameter.
* By default, the response status code is 301.
*
* If the route empty, the status code will be 410.
* If the permanent path parameter is set, the status code will be 302.
*
* @param string $route The route pattern to redirect to
* @param Boolean $permanent Whether the redirect is permanent or not
*
* @return Response A Response instance
*/
public function redirectAction($route, $permanent = false)
{
if (!$route) {
$response = $this->container->getResponseService();
$response = $this['response'];
$response->setStatusCode(410);

return $response;
}

$code = $permanent ? 301 : 302;

$parameters = $this->getRequest()->getPathParameters();
unset($parameters['_route'], $parameters['route']);
$attributes = $this['request']->attributes->all();
unset($attributes['_route'], $attributes['route']);

$response = $this['response'];
$response->setRedirect($this['router']->generate($route, $attributes), $code);

return $this->redirect($this->container->getRouterService()->generate($route, $parameters), $code);
return $response;
}
}
Expand Up @@ -3,6 +3,7 @@
namespace Symfony\Bundle\FrameworkBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller;
use Symfony\Components\HttpFoundation\Response;

/*
* This file is part of the Symfony framework.
Expand All @@ -20,8 +21,15 @@
*/
class TemplateController extends Controller
{
/**
* Renders a template.
*
* @param string $template The template name
*
* @return Response A Response instance
*/
public function templateAction($template)
{
return $this->render($template);
return $this['templating']->renderResponse($template);
}
}

0 comments on commit 714fa6f

Please sign in to comment.