DataObjects as Pages (SSBits Tutorial) - Sivlerstripe 3

牧云@^-^@ 提交于 2019-12-13 09:55:24

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!