PHP code example of stnvh / silverstripe-taggedfield

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

    

stnvh / silverstripe-taggedfield example snippets




class MyObject extends DataObject {

	private static $db = array(
		'Tags' => 'Text'
	);

	public function getCMSFields() {
		$fields = parent::getCMSFields();

		$taggedField = TaggedField::create('Tags');

		$fields->addFieldToTab('Root.Main', $taggedField);

		return $fields;
	}

	// To use the tags in the template correctly
	public function Tags() {
		$tags = explode(',', $this->Tags);
		foreach($tags as $i => $tag) {
			$tags[$i] = array('Tag' => $tag);
		}
		return ArrayList::create($tags);
	}

}