symfony API

sfRouting Class

« Back to API menu

action

addon

cache

config

controller

countable

database

debug

exception

filter

generator

helper

i18n

log

request

response

storage

test

user

util

validator

view

You are currently browsing the symfony documentation for the 1.0 version. Switch to:

sfRouting class controls the creation of URLs and parses URLs. It maps an array of parameters to URLs definition.

Method Summary

  • appendRoute($name, $route, $default = array(), $requirements = array())
    Adds a new route.
  • prependRoute($name, $route, $default = array(), $requirements = array())
    Adds a new route at the beginning of the current list of routes.
  • getInstance()
    Retrieve the singleton instance of this class.
  • array parse($url)
    Parses a URL to find a matching route.
  • array connect($name, $route, $default = array(), $requirements = array())
    Adds a new route at the end of the current list of routes.
  • string getCurrentInternalUri($with_route_name = false)
    Gets the internal URI for the current request.
  • array setRoutes($routes)
    Sets the compiled route array.
  • boolean hasRouteName($name)
    Returns true if the route name given is defined.
  • clearRoutes()
    Clears all current routes.
  • boolean hasRoutes()
    Returns true if this instance has some routes.
  • string getCurrentRouteName()
    Gets the current route name.
  • array getRouteByName($name)
    Gets a route by its name.
  • string generate($name, $params, $querydiv = '/', $divider = '/', $equals = '/')
    Generates a valid URLs for parameters.
  • array getRoutes()
    Gets the current compiled route array.
  • setCurrentRouteName($name)
    Sets the current route name.

Method Details

  • appendRoute ($name, $route, $default = array(), $requirements = array())

    Adds a new route.

    Alias for the connect method.

  • prependRoute ($name, $route, $default = array(), $requirements = array())

    Adds a new route at the beginning of the current list of routes.

  • getInstance ()

    Retrieve the singleton instance of this class.

    returns The sfRouting implementation instance

  • (array) parse ($url)

    $url URL to be parsed

    Parses a URL to find a matching route.

    Returns null if no route match the URL.

    returns An array of parameters

  • (array) connect ($name, $route, $default = array(), $requirements = array())

    $name The route name
    $route The route string
    $default The default parameter values
    $requirements The regexps parameters must match

    Adds a new route at the end of the current list of routes.

    A route string is a string with 2 special constructions:


    • :string: :string denotes a named paramater (available later as $request->getParameter('string'))

    • *: * match an indefinite number of parameters in a route



    Here is a very common rule in a symfony project:
     $r->connect('/:module/:action/*');

    returns current routes

  • (string) getCurrentInternalUri ($with_route_name = false)

    $with_route_name Whether to give an internal URI with the route name (@route) or with the module/action pair

    Gets the internal URI for the current request.

    returns The current internal URI

  • (array) setRoutes ($routes)

    $routes The route array

    Sets the compiled route array.

    returns The route array

  • (boolean) hasRouteName ($name)

    $name The route name

    Returns true if the route name given is defined.

  • clearRoutes ()

    Clears all current routes.

  • (boolean) hasRoutes ()

    Returns true if this instance has some routes.

  • (string) getCurrentRouteName ()

    Gets the current route name.

    returns The route name

  • (array) getRouteByName ($name)

    $name The route name

    Gets a route by its name.

    returns A route array

  • (string) generate ($name, $params, $querydiv = '/', $divider = '/', $equals = '/')

    $name The parameter values
    $params The divider between key/value pairs
    $querydiv The equal sign to use between key and value

    Generates a valid URLs for parameters.

    returns The generated URL

  • (array) getRoutes ()

    Gets the current compiled route array.

    returns The route array

  • setCurrentRouteName ($name)

    $name The route name

    Sets the current route name.