PHP Classes

File: manuscript/6d.-Generating URLs.md

Recommend this page to a friend!
  Classes of Gjero Krsteski   PIMF   manuscript/6d.-Generating URLs.md   Download  
File: manuscript/6d.-Generating URLs.md
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: PIMF
Framework for Web application development
Author: By
Last change: Update of manuscript/6d.-Generating URLs.md
Date: 5 months ago
Size: 1,377 bytes
 

Contents

Class file image Download

Generating URLs

Retrieving the application's base URL:

$url = URL::base();

Generating a URL relative to the base URL:

$url = URL::to('user/show');

Generating a HTTPS URL:

$url = URL::asHttps('user/login');

Retrieving the current URL:

$url = URL::current();

Retrieving the current URL including query string:

$url = URL::full();

URLs To Routes

Generating a URL to a named route:

$url = URL::toRoute('user/show');

Sometimes you may need to generate a URL to a named route, but also need to specify the values that should be used instead of the route's URI wildcards. It's easy to replace the wildcards with proper values:

Generating a URL to a named route with wildcard values:

$url = URL::compute('user/profile', array($username));

URLs To Controller Actions

Generating a URL to a controller action:

$url = URL::compute('user/show');

Generating a URL to an action with wildcard values:

$url = URL::compute('user/show', array($username));

URLs To Assets

Generating a URL to an asset:

$url = URL::toAsset('js/jquery.js');

URL Helpers

There are several global functions for generating URLs designed to make your life easier and your code cleaner:

Generating a URL relative to the base URL:

$url = Pimf\url('user/show');