Gc\Document\Model::getUrl PHP Method

getUrl() public method

Get document url
public getUrl ( boolean $forceCanonical = false ) : string
$forceCanonical boolean Force canonical url
return string
    public function getUrl($forceCanonical = false)
    {
        $parent = $this->getParent();
        $path = $this->getUrlKey();
        if (!empty($parent)) {
            $path = $parent->getUrl() . '/' . $path;
        }
        $url = '/' . ltrim($path, '/');
        if ($forceCanonical) {
            $serverUrl = Registry::get('Application')->getServiceManager()->get('ViewHelperManager')->get('ServerUrl');
            $url = $serverUrl() . $url;
        }
        return $url;
    }

Usage Example

Example #1
0
 /**
  * Test
  *
  * @return void
  */
 public function testGetUrl()
 {
     $this->assertEquals('/parent/url-key', $this->object->getUrl());
     $this->assertEquals('http:///parent/url-key', $this->object->getUrl(true));
 }