我创建了一个支持两种语言(ar / en)的网站,并创建了新闻栏目和新闻记者。在新闻持有者中我想获取当前语言的新闻,我的新闻页面都是用两种语言翻译的,在默认的英语语言中,我得到了所有的预期英语新闻,而不是其他语言。
查询新闻页面时可能需要做一些事情,查询结果应该返回基于当前所选语言环境和语言的记录。
这是我收到新闻文章的地方:
<?php
class HomePage extends Page
{
}
class HomePage_Controller extends Page_Controller
{
public function LatestNews($limit = 2)
{
$articles = NewsArticle::get()->sort(array('"OriginalPublishedDate" DESC'))
->limit($limit);
return $articles;
}
,这是NewsArticle的数据库定义
class NewsArticle extends Page {
private static $icon = 'news/images/newspaper';
private static $db = array(
'Summary' => 'HTMLText',
'Author' => 'Varchar(128)',
'OriginalPublishedDate' => 'Date',
'ExternalURL' => 'Varchar(255)',
'Source' => 'Varchar(128)',
);
/**
* The InternalFile is used when the news article is mostly contained in a file based item -
* if this is set, then the URL to the item is returned in the call to "Link" for this asset.
*
* @var array
*/
private static $has_one = array(
'InternalFile' => 'File',
'NewsSection' => 'NewsHolder',
'Thumbnail' => 'Image',
);