问题
I tried to use this tutorial http://www.ssbits.com/tutorials/2010/dataobjects-as-pages-part-2-using-model-admin-and-url-segments-to-create-a-product-catalogue/ from ssbits for my news section.
I think I did everything right. But I can't save the NewsObject. This error appears
Notice at line 155 of /mysite/code/DataObjects/NewsObject.php
Line 155 is this
$this->URLSegment = SiteTree::generateURLSegment($this->Title);
But what's wrong here?
Here's my whole code. Perhaps someone can help me to solve this problem.
NewsObject: http://www.sspaste.com/paste/show/5278c59fd7904
NewsCategory: http://www.sspaste.com/paste/show/5268d844c9ee2
回答1:
This is how the DataObjects-as-Pages module does it:
$this->URLSegment = $this->generateURLSegment($this->Title);
This uses a custom function in the same class:
public function generateURLSegment($title)
{
$filter = URLSegmentFilter::create();
$t = $filter->filter($title);
// Fallback to generic page name if path is empty (= no valid, convertable characters)
if(!$t || $t == '-' || $t == '-1') $t = "page-$this->ID";
// Hook for extensions
$this->extend('updateURLSegment', $t, $title);
return $t;
}
来源:https://stackoverflow.com/questions/19560804/dataobjects-as-pages-ssbits-tutorial-sivlerstripe-3