質問

I'm fairly new to silverstripe and php altogether so this is quite the learning curve for me. I am well familiarized with MVC frameworks such as Rails so I don't think I'm completely lost; however I did spend quite a few days on this now and I just can't seem to figure it out.

I am trying to implement tags functionality on my website. For example I have ArticleHolder which lists ArticleNews and I have created a text field in ArticleNews called Tags. User can, when creating new article, enter tags and separate them by comma.

What I don't know how to do is grab all the news articles, search by tag and then return only those that contain the tag News.

public function PaginatedPages() { 
$paginatedItems = new PaginatedList(getNewsArticles()->sort('Date DESC'), $this->request); 
$paginatedItems->setPageLength(3); 
return $paginatedItems; 
} 
public function getNewsArticles(){ 
$newsArticles = ArticlePage::get();

foreach ($newsArticles as article){ 
$categories = article::get('category');

} 
return $newsArticles; 
}

I am not certain on how to grab the data from the tags text field and then check if the News is in there. If it is not I want to remove it from $newsArticles.

That is my second question, how do I remove the ArticleNews from $newsArticle.

My third question is, can I do this on the database end? So simply ::get() from the database where Tags contain the word News. The delimiter is comma ','

役に立ちましたか?

解決

If you want to filter the list by a particular tag

$articles = ArticlePage::get()->filter('Tags:PartialMatch', 'News')

Though implementing tags with something like the TagField module would be better than comma separated strings. http://addons.silverstripe.org/add-ons/silverstripe/tagfield

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top