Yosymfony\Spress\Core\Plugin\Event\RenderEvent::setRelativeUrl PHP Method

setRelativeUrl() public method

Sets the relative URL (only path component) of the item.
public setRelativeUrl ( string $url )
$url string The relative URL. e.g: /about/me/index.html
    public function setRelativeUrl($url)
    {
        $url = $this->prepareUrl($url);
        $attributes = $this->getAttributes();
        $attributes['url'] = $url;
        $urlPath = $this->getPathFromUrl($url);
        $this->item->setPath($urlPath, ItemInterface::SNAPSHOT_PATH_PERMALINK);
        $this->setAttributes($attributes);
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @expectedException \RuntimeException
  */
 public function testUrlWithoutStartWithSlash()
 {
     $item = new Item('Test of content', 'index.html', ['title' => 'My posts']);
     $event = new RenderEvent($item, Item::SNAPSHOT_RAW, Item::SNAPSHOT_PATH_RELATIVE);
     $event->setRelativeUrl('index.html');
 }