* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Bundle\FrameworkBundle\Controller; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\DependencyInjection\ContainerAware; /** * Controller is a simple implementation of a Controller. * * It provides methods to common features needed in controllers. * * @author Fabien Potencier */ class Controller extends ContainerAware { /** * Generates a URL from the given parameters. * * @param string $name The name of the route * @param array $parameters An array of parameters * @param Boolean $absolute Whether to generate an absolute URL * * @return string The generated URL */ public function generateUrl($route, array $parameters = array(), $absolute = false) { return $this->container->get('router')->generate($route, $parameters, $absolute); } /** * Forwards the request to another controller. * * @param string $controller The controller name (a string like BlogBundle:Post:index) * @param array $path An array of path parameters * @param array $query An array of query parameters * * @return Response A Response instance */ public function forward($controller, array $path = array(), array $query = array()) { return $this->container->get('http_kernel')->forward($controller, $path, $query); } /** * Returns a rendered view. * * @param string $view The view name * @param array $parameters An array of parameters to pass to the view * * @return string The renderer view */ public function renderView($view, array $parameters = array()) { return $this->container->get('templating')->render($view, $parameters); } /** * Renders a view. * * @param string $view The view name * @param array $parameters An array of parameters to pass to the view * @param Response $response A response instance * * @return Response A Response instance */ public function render($view, array $parameters = array(), Response $response = null) { return $this->container->get('templating')->renderResponse($view, $parameters, $response); } /** * Returns true if the service id is defined. * * @param string $id The service id * * @return Boolean true if the service id is defined, false otherwise */ public function has($id) { return $this->container->has($id); } /** * Gets a service by id. * * @param string $id The service id * * @return object The service */ public function get($id) { return $this->container->get($id); } }