waRouting

Manages HTTP request related data

Contents...

To obtain an instance of waRouting class and call its public non-static methods, use wa()->getRouting(); e.g.:

wa()->getRouting()->getCurrentUrl();

Methods

public static function clearUrl ($url)

Removes special characters from routing rule address.

Parameters

Example

waRouting::clearUrl('site/*');

Result

'site/'

public function getByApp ($app_id, $domain = null)

Returns all routing rules set up for the frontends of specified app.

Parameters

Example 1

wa()->getRouting()->getByApp('shop');

Result

array(
  'domain1.com' => array(
    1 => array(
      'url' => '*',
      'app' => 'shop',
      '_name' => 'Store #1',
      'theme' => 'default',
      'theme_mobile' => 'default',
      'locale' => 'en_US',
      'title' => '',
      'meta_keywords' => '',
      'meta_description' => '',
      'og_title' => '',
      'og_image' => '',
      'og_video' => '',
      'og_description' => '',
      'og_type' => '',
      'url_type' => '1',
      'type_id' => '0',
      'currency' => 'USD',
      'stock_id' => '1',
      'public_stocks' => '0',
      'drop_out_of_stock' => '2',
      'payment_id' => '0',
      'shipping_id' => '0',
    ),
  ),
  'domain2.com' => array(
    3 => array(
      'url' => 'shop/*',
      'app' => 'shop',
      '_name' => 'Store #2',
      'theme' => 'custom',
      'theme_mobile' => 'mobile',
      'locale' => 'en_US',
      'title' => '',
      'meta_keywords' => '',
      'meta_description' => '',
      'og_title' => '',
      'og_image' => '',
      'og_video' => '',
      'og_description' => '',
      'og_type' => '',
      'url_type' => '0',
      'type_id' => '0',
      'currency' => 'USD',
      'stock_id' => '2',
      'public_stocks' => '0',
      'drop_out_of_stock' => '0',
      'payment_id' => '0',
      'shipping_id' => '0',
    ),
  ),
)

Example 2

wa()->getRouting()->getByApp('shop', 'domain1.com')

Result

array(
  'url' => '*',
  'app' => 'shop',
  '_name' => 'Shop #1',
  'theme' => 'default',
  'theme_mobile' => 'default',
  'locale' => 'en_US',
  'title' => '',
  'meta_keywords' => '',
  'meta_description' => '',
  'og_title' => '',
  'og_image' => '',
  'og_video' => '',
  'og_description' => '',
  'og_type' => '',
  'url_type' => '1',
  'type_id' => '0',
  'currency' => 'USD',
  'stock_id' => '1',
  'public_stocks' => '0',
  'drop_out_of_stock' => '2',
  'payment_id' => '0',
  'shipping_id' => '0',
),

public function getCurrentUrl()

Returns relative URL of current HTTP request with GET parameters removed.

Example

$current_url = wa()->getRouting()->getCurrentUrl();

public function getDomain ($domain = null, $check = false, $return_alias = true)

Returns site URL parsed from the URL of current HTTP request, or specified site's URL.

Parameters

Example

$main_site_domain = wa()->getRouting()->getDomain(null, false, true);

public function getDomains()

Returns array of all sites' URLs.

Example

wa()->getRouting()->getDomains();

Result

array(
  0 => 'domain1.com',
  1 => 'domain2.com',
  2 => 'domain3.com',
)

public function getRootUrl()

Returns root URL of the routing rule matching current HTTP request in frontend.

Example

wa()->getRouting()->getRootUrl();

Result

//for routing rule with URL shop/*
'shop/'
    
//for routing rule with URL *
''

public function getRoute ($name = null)

Returns parameters of the routing rule matching current HTTP request in frontend.

Parameters

Example 1

wa()->getRouting()->getRoute();

Result

array(
  'url' => 'site/*',
  'app' => 'site',
  'theme' => 'default',
  'theme_mobile' => 'default',
  'locale' => 'en_US',
)

Example 2

wa()->getRouting()->getRoute('theme');

Result

'default'

public function getRoutes ($domain = null)

Returns array of routing rules of specified or current site.

Parameters

Example

wa()->getRouting()->getRoutes();

Result

array(
  3 => array(
    'url' => 'site/*',
    'app' => 'site',
    'theme' => 'default',
    'theme_mobile' => 'default',
    'locale' => 'en_US',
  ),
  2 => array(
    'url' => 'photos/*',
    'app' => 'photos',
    'theme' => 'default',
    'theme_mobile' => 'default',
    'locale' => 'en_US',
    'url_type' => '0',
    'title' => '',
    'meta_keywords' => '',
    'meta_description' => '',
  ),
  1 => array(
    'url' => '*',
    'app' => 'shop',
    'theme' => 'default',
    'theme_mobile' => 'default',
    'locale' => 'en_US',
    'title' => '',
    'meta_keywords' => '',
    'meta_description' => '',
    'og_title' => '',
    'og_image' => '',
    'og_video' => '',
    'og_description' => '',
    'og_type' => '',
    'url_type' => '1',
    'type_id' => '0',
    'currency' => 'USD',
    'stock_id' => '7',
    'public_stocks' => '0',
    'drop_out_of_stock' => '2',
    'payment_id' => '0',
    'shipping_id' => '0',
  ),
)

public function getUrl ($path, $params = array(), $absolute = false, $domain_url = null, $route_url = null)

Returns URL for a frontend request generated from specified routing parameters.

Parameters

Example

wa()->getRouting()->getUrl(
    'shop/frontend/category/<category_url>/',
    array('category_url' => 'sale'),
    true,
    'domain2.com',
    'facebook/*'
);

Result

'http://domain2.com/facebook/category/sale/'

public static function getUrlByRoute ($route, $domain = null)

Returns root URL for a frontend request for specified routing rule.

Parameters

Example

waRouting::getUrlByRoute(
    array('url' => 'shop/*'),
    'domain.com'
);

Result

'http://domain.com/shop/'

public function isAlias ($domain)

Returns address of of main site for specified alias.

Parameters

Example

wa()->getRouting()->isAlias('alias-domain.com');

Result

'main-domain.com'