本文整理汇总了PHP中SiteTree::generateURLSegment方法的典型用法代码示例。如果您正苦于以下问题:PHP SiteTree::generateURLSegment方法的具体用法?PHP SiteTree::generateURLSegment怎么用?PHP SiteTree::generateURLSegment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SiteTree
的用法示例。
在下文中一共展示了SiteTree::generateURLSegment方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onBeforeWrite
function onBeforeWrite()
{
// If there is no URLSegment set, generate one from Title
if ((!$this->URLSegment || $this->URLSegment == 'new-offer') && $this->Title != 'New Offer') {
$this->URLSegment = @SiteTree::generateURLSegment($this->Name);
} else {
if ($this->isChanged('URLSegment')) {
// Make sure the URLSegment is valid for use in a URL
$segment = preg_replace('/[^A-Za-z0-9]+/', '-', $this->URLSegment);
$segment = preg_replace('/-+/', '-', $segment);
// If after sanitising there is no URLSegment, give it a reasonable default
if (!$segment) {
$segment = "Offer-{$this->ID}";
}
$this->URLSegment = $segment;
}
}
// Ensure that this object has a non-conflicting URLSegment value.
$count = 2;
while ($this->LookForExistingURLSegment($this->URLSegment)) {
$this->URLSegment = preg_replace('/-[0-9]+$/', null, $this->URLSegment) . '-' . $count;
$count++;
}
parent::onBeforeWrite();
}
示例2: onBeforeWrite
/**
* Updates the group so the security section is also in sync with
* the curent newsletters.
*/
function onBeforeWrite()
{
if ($this->ID) {
$group = $this->Group();
if ($group->Title != "{$this->Title}") {
$group->Title = _t('NewsletterType.MAILINGLIST', 'Mailing List:') . ' ' . $this->Title;
// Otherwise the code would have mailing list in it too :-(
$group->Code = SiteTree::generateURLSegment($this->Title);
$group->write();
}
}
parent::onBeforeWrite();
}
示例3: onBeforeWrite
function onBeforeWrite()
{
parent::onBeforeWrite();
if (isset($_POST['AlbumName'])) {
$clean_name = SiteTree::generateURLSegment($_POST['AlbumName']);
if ($this->FolderID) {
$this->Folder()->setName($clean_name);
$this->Folder()->Title = $clean_name;
$this->Folder()->write();
} else {
$folder = Folder::findOrMake('image-gallery/' . $this->ImageGalleryPage()->RootFolder()->Name . '/' . $clean_name);
$this->FolderID = $folder->ID;
}
}
}
示例4: setCode
/**
* Overloaded to ensure the code is always descent.
*/
public function setCode($val)
{
$this->setField("Code", SiteTree::generateURLSegment($val));
}