symfony API

UrlHelper Functions

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to API menu

1.2 API OpenSearch

Packages

You are currently browsing the symfony API for the 1.2 version. Switch to:
This version of symfony is not maintained anymore.
If some of your projects still use this version, consider upgrading as soon as possible.

UrlHelper.

Function Summary

  • string button_to($name, $internal_uri, $options = array())
    Creates an <input> button tag of the given name pointing to a routed URL based on the module/action passed as argument and the routing configuration.
  • form_tag_for($form, $routePrefix, $attributes = array())
  • string link_to($name, $internal_uri, $options)
    Creates a <a> link tag of the given name using a routed URL based on the module/action passed as argument and the routing configuration.
  • link_to1($name, $internal_uri, $options = array())
  • link_to2($name, $routeName, $params, $options = array())
  • string link_to_if($condition, $name = '', $internal_uri = '', $options = array())
    If the condition passed as first argument is true, creates a <a> link tag of the given name using a routed URL based on the module/action passed as argument and the routing configuration.
  • string link_to_unless($condition, $name = '', $internal_uri = '', $options = array())
    If the condition passed as first argument is false, creates a <a> link tag of the given name using a routed URL based on the module/action passed as argument and the routing configuration.
  • string mail_to($email, $name = '', $options = array(), $default_value = array())
    Creates a <a> link tag to the given email (with href="mailto:...").
  • The public_path($path, $absolute = false)
    Returns a URL rooted at the web root
  • string url_for($internal_uri, $absolute)
    Returns a routed URL based on the module/action passed as argument and the routing configuration.
  • url_for1($internal_uri, $absolute = false)
  • url_for2($routeName, $params = array(), $absolute = false)
  • url_for_form($form, $routePrefix)
  • _confirm_javascript_function($confirm)
  • _convert_options_to_javascript($html_options, $url = 'this.href')
  • _encodeText($text)
  • _method_javascript_function($method)
  • _popup_javascript_function($popup, $url = '')
  • _post_javascript_function()

Function Details

  • (string) button_to ($name, $internal_uri, $options = array()) Browse code

    $name name of the button
    $internal_uri 'module/action' or '@rule' of the action
    $options additional HTML compliant <input> tag parameters

    Creates an &lt;input&gt; button tag of the given name pointing to a routed URL based on the module/action passed as argument and the routing configuration.


    The syntax is similar to the one of link_to.

    Options:


    • 'absolute' - if set to true, the helper outputs an absolute URL

    • 'query_string' - to append a query string (starting by ?) to the routed url

    • 'anchor' - to append an anchor (starting by #) to the routed url

    • 'confirm' - displays a javascript confirmation alert when the button is clicked

    • 'popup' - if set to true, the button opens a new browser window

    • 'post' - if set to true, the button submits a POST request instead of GET (caution: do not use inside a form)



    Examples:
      echo button_to('Delete this page', 'my_module/my_action');
    
    => <input value=\"Delete this page\" type=\"button\" onclick=\"document.location.href='/path/to/my/action';\" />

    returns XHTML compliant <input> tag

  • form_tag_for ($form, $routePrefix, $attributes = array()) Browse code

    $form
    $routePrefix
    $attributes

  • (string) link_to ($name, $internal_uri, $options) Browse code

    $name name of the link, i.e. string to appear between the <a> tags
    $internal_uri 'module/action' or '@rule' of the action
    $options additional HTML compliant <a> tag parameters

    Creates a &lt;a&gt; link tag of the given name using a routed URL based on the module/action passed as argument and the routing configuration.


    It's also possible to pass a string instead of a module/action pair to get a link tag that just points without consideration. If null is passed as a name, the link itself will become the name. If an object is passed as a name, the object string representation is used. One of the options serves for for creating javascript confirm alerts where if you pass 'confirm' => 'Are you sure?', the link will be guarded with a JS popup asking that question. If the user accepts, the link is processed, otherwise not.

    Options:


    • 'absolute' - if set to true, the helper outputs an absolute URL

    • 'query_string' - to append a query string (starting by ?) to the routed url

    • 'anchor' - to append an anchor (starting by #) to the routed url

    • 'confirm' - displays a javascript confirmation alert when the link is clicked

    • 'popup' - if set to true, the link opens a new browser window

    • 'post' - if set to true, the link submits a POST request instead of GET (caution: do not use inside a form)

    • 'method' - if set to post, delete, or put, the link submits a request with the given HTTP method instead of GET (caution: do not use inside a form)



    Note: The 'popup', 'post', and 'method' options are not compatible with each other.

    Examples:

      echo link_to('Delete this page', 'my_module/my_action');
    
    => <a href=\"/path/to/my/action\">Delete this page</a>
    echo link_to('Visit Hoogle', 'http://www.hoogle.com');
    => <a href=\"http://www.hoogle.com\">Visit Hoogle</a>
    echo link_to('Delete this page', 'my_module/my_action', array('id' => 'myid', 'confirm' => 'Are you sure?', 'absolute' => true));
    => <a href=\"http://myapp.example.com/path/to/my/action\" id=\"myid\" onclick=\"return confirm('Are you sure?');\">Delete this page</a>

    returns XHTML compliant <a href> tag

  • link_to1 ($name, $internal_uri, $options = array()) Browse code

    $name
    $internal_uri
    $options

  • link_to2 ($name, $routeName, $params, $options = array()) Browse code

    $name
    $routeName
    $params
    $options

  • (string) link_to_if ($condition, $name = '', $internal_uri = '', $options = array()) Browse code

    $condition condition
    $name name of the link, i.e. string to appear between the <a> tags
    $internal_uri 'module/action' or '@rule' of the action
    $options additional HTML compliant <a> tag parameters

    If the condition passed as first argument is true, creates a &lt;a&gt; link tag of the given name using a routed URL based on the module/action passed as argument and the routing configuration.


    If the condition is false, the given name is returned between <span> tags

    Options:


    • 'tag' - the HTML tag that must enclose the name if the condition is false, defaults to <span>

    • 'absolute' - if set to true, the helper outputs an absolute URL

    • 'query_string' - to append a query string (starting by ?) to the routed url

    • 'anchor' - to append an anchor (starting by #) to the routed url

    • 'confirm' - displays a javascript confirmation alert when the link is clicked

    • 'popup' - if set to true, the link opens a new browser window

    • 'post' - if set to true, the link submits a POST request instead of GET (caution: do not use inside a form)



    Examples:
      echo link_to_if($user->isAdministrator(), 'Delete this page', 'my_module/my_action');
    
    => <a href=\"/path/to/my/action\">Delete this page</a>
    echo link_to_if(!$user->isAdministrator(), 'Delete this page', 'my_module/my_action');
    => <span>Delete this page</span>

    returns XHTML compliant <a href> tag or name

  • (string) link_to_unless ($condition, $name = '', $internal_uri = '', $options = array()) Browse code

    $condition condition
    $name name of the link, i.e. string to appear between the <a> tags
    $internal_uri 'module/action' or '@rule' of the action
    $options additional HTML compliant <a> tag parameters

    If the condition passed as first argument is false, creates a &lt;a&gt; link tag of the given name using a routed URL based on the module/action passed as argument and the routing configuration.


    If the condition is true, the given name is returned between <span> tags

    Options:


    • 'tag' - the HTML tag that must enclose the name if the condition is true, defaults to <span>

    • 'absolute' - if set to true, the helper outputs an absolute URL

    • 'query_string' - to append a query string (starting by ?) to the routed url

    • 'anchor' - to append an anchor (starting by #) to the routed url

    • 'confirm' - displays a javascript confirmation alert when the link is clicked

    • 'popup' - if set to true, the link opens a new browser window

    • 'post' - if set to true, the link submits a POST request instead of GET (caution: do not use inside a form)



    Examples:
      echo link_to_unless($user->isAdministrator(), 'Delete this page', 'my_module/my_action');
    
    => <span>Delete this page</span>
    echo link_to_unless(!$user->isAdministrator(), 'Delete this page', 'my_module/my_action');
    => <a href=\"/path/to/my/action\">Delete this page</a>

    returns XHTML compliant <a href> tag or name

  • (string) mail_to ($email, $name = '', $options = array(), $default_value = array()) Browse code

    $email target email
    $name name of the link, i.e. string to appear between the <a> tags
    $options additional HTML compliant <a> tag parameters
    $default_value

    Creates a &lt;a&gt; link tag to the given email (with href=&quot;mailto:...&quot;).


    If null is passed as a name, the email itself will become the name.

    Options:


    • 'encode' - if set to true, the email address appears with various random encoding for each letter.



    The mail link still works when encoded, but the address doesn't appear in clear in the source. Use it to prevent spam (efficiency not guaranteed).

    Examples:

      echo mail_to('webmaster@example.com');
    
    => <a href=\"mailto:webmaster@example.com\">webmaster@example.com</a>
    echo mail_to('webmaster@example.com', 'send us an email');
    => <a href=\"mailto:webmaster@example.com\">send us an email</a>
    echo mail_to('webmaster@example.com', 'send us an email', array('encode' => true));
    => <a href=\"

    returns XHTML compliant <a href> tag

  • (The) public_path ($path, $absolute = false) Browse code

    $path The route to append
    $absolute If true, an absolute path is returned (optional)

    Returns a URL rooted at the web root

    returns web URL root

  • (string) url_for ($internal_uri, $absolute) Browse code

    $internal_uri 'module/action' or '@rule' of the action
    $absolute return absolute path?

    Returns a routed URL based on the module/action passed as argument and the routing configuration.


    Examples:

      echo url_for('my_module/my_action');
    
    => /path/to/my/action
    echo url_for('@my_rule');
    => /path/to/my/action
    echo url_for('@my_rule', true);
    => http://myapp.example.com/path/to/my/action

    returns routed URL

  • url_for1 ($internal_uri, $absolute = false) Browse code

    $internal_uri
    $absolute

  • url_for2 ($routeName, $params = array(), $absolute = false) Browse code

    $routeName
    $params
    $absolute

  • url_for_form ($form, $routePrefix) Browse code

    $form
    $routePrefix

  • _confirm_javascript_function ($confirm) Browse code

    $confirm

  • _convert_options_to_javascript ($html_options, $url = 'this.href') Browse code

    $html_options
    $url

  • _encodeText ($text) Browse code

    $text

  • _method_javascript_function ($method) Browse code

    $method

  • _popup_javascript_function ($popup, $url = '') Browse code

    $popup
    $url

  • _post_javascript_function () Browse code