public function tag($tags, $clearExisting = false) {
		if (!is_array($tags)) {
			$tags = array($tags);
		}

		if ($clearExisting) {
			$this->Tags()->removeAll();
		}

		$created = array();
		foreach ($tags as $tag) {
			if (!preg_match('/[a-z0-9_-]/i', $tag)) {
				continue;
			}
			$existing = PostTag::get()->filter(array('Title' => $tag))->first();
			if (!$existing) {
				$existing = PostTag::create();
				$existing->Title = $tag;
				$existing->write();
			}
			$this->Tags()->add($existing, array('Tagged' => date('Y-m-d H:i:s')));
			$created[] = $existing;
		}
		return $created;
	}
public function tag($tags, $clearExisting = false) {
		if (!is_array($tags)) {
			$tags = array($tags);
		}

		if ($clearExisting) {
			$this->Tags()->removeAll();
		}

		$created = array();
		foreach ($tags as $tag) {
			if (!preg_match('/[a-z0-9_-]/i', $tag)) {
				continue;
			}
			$existing = PostTag::get()->filter(array('Title' => $tag))->first();
			if (!$existing) {
				$existing = PostTag::create();
				$existing->Title = $tag;
				$existing->write();
			}
			$this->Tags()->add($existing, array('Tagged' => date('Y-m-d H:i:s')));
			$created[] = $existing;
		}
		return $created;
	}
public function tag ( $ tags , $ clearExisting = false ) { if ( ! is_array ( $ tags ) ) { $ tags = array ( $ tags ) ; } if ( $ clearExisting ) { $ this -> Tags ( ) -> removeAll ( ) ; } $ created = array ( ) ; foreach ( $ tags as $ tag ) { if ( ! preg_match ( '/[a-z0-9_-]/i' , $ tag ) ) { continue ; } $ existing = PostTag :: get ( ) -> filter ( array ( 'Title' => $ tag ) ) -> first ( ) ; if ( ! $ existing ) { $ existing = PostTag :: create ( ) ; $ existing -> Title = $ tag ; $ existing -> write ( ) ; } $ this -> Tags ( ) -> add ( $ existing , array ( 'Tagged' => date ( 'Y-m-d H:i:s' ) ) ) ; $ created [ ] = $ existing ; } return $ created ; }
Tag this post with a particular tag

@param string $tag
Tag this post with a particular tag