PHP code example of silverstripe / sitetreeimporter
1. Go to this page and download the library: Download silverstripe/sitetreeimporter library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
silverstripe / sitetreeimporter example snippets
class Page extends SiteTree {
public function setLegacyURL($url) {
$url = Director::makeRelative($url);
$urlBase = parse_url($url, PHP_URL_PATH);
$urlQuerystring = parse_url($url, PHP_URL_QUERY);
$urlObj = RedirectedURL::get()->filter(array(
'FromBase' => $urlBase,
'FromQuerystring' => $urlQuerystring
))->First();
if(!$urlObj) {
$urlObj = new RedirectedURL();
}
$urlObj->FromBase = $urlBase;
$urlObj->FromQuerystring = $urlQuerystring;
if(!$this->URLSegment) {
$this->URLSegment = $this->generateURLSegment($this->Title);
}
$urlObj->To = $this->RelativeLink();
$urlObj->write();
}
}