PHP code example of zauberfisch / silverstripe-urlsegment-extension

1. Go to this page and download the library: Download zauberfisch/silverstripe-urlsegment-extension 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/ */

    

zauberfisch / silverstripe-urlsegment-extension example snippets




/**
* @property string $Title
* @method \SilverStripe\CMS\Model\SiteTree TeamPage()
 */
class TeamMember extends \SilverStripe\ORM\DataObject {
    private static $db = [
        'Title' => \SilverStripe\ORM\FieldType\DBVarchar::class,
    ];
    private static $has_one = [
        'TeamPage' => \SilverStripe\CMS\Model\SiteTree::class,
    ];

    private static $extensions = [
        \zauberfisch\URLSegmentExtension\URLSegmentDataExtension::class,
    ];

    public function getCMSFields() {
        $urlPrefix = $this->TeamPage()->Link();
        $urlSuffix = "";
        $fields = parent::getCMSFields();
        $fields->removeByName('URLSegment');
        $fields->addFieldsToTab( 'Root.Main', [
            new \zauberfisch\URLSegmentExtension\URLSegmentFormField('URLSegment', $this->fieldLabel('URLSegment'), $urlPrefix, $urlSuffix),
        ]);
        return $fields;
    }
}