Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php SilverStripe可翻译保存值在默认区域设置中,并将其复制到非默认区域设置_Php_Translation_Silverstripe - Fatal编程技术网

Php SilverStripe可翻译保存值在默认区域设置中,并将其复制到非默认区域设置

Php SilverStripe可翻译保存值在默认区域设置中,并将其复制到非默认区域设置,php,translation,silverstripe,Php,Translation,Silverstripe,我用SilverStripe3.1.13(CMS和框架)构建了我的项目,我正在使用SilverStripe translateable和dataobjecttranslateable来组织我在网站上的翻译 假设我有Post.php(这是DataObject,用于在我的网站上处理帖子),每个帖子都有自己的类别(many-many关系在这里,但这并不重要) 问题是:在创建新的Post数据对象时,我点击了Save按钮,我希望这些类别将自动复制到其他地区 我如何在我的应用程序中实现这一点?我想将这些值(

我用
SilverStripe
3.1.13(CMS和框架)构建了我的项目,我正在使用
SilverStripe translateable
dataobjecttranslateable
来组织我在网站上的翻译

假设我有
Post.php
(这是
DataObject
,用于在我的网站上处理帖子),每个帖子都有自己的
类别(
many-many
关系在这里,但这并不重要)

问题是:在创建新的
Post
数据对象时,我点击了
Save
按钮,我希望这些
类别将自动复制到其他地区


我如何在我的应用程序中实现这一点?我想将这些值(它们是布尔值)保存到这些数据对象的另一个翻译中。

可能没有内置功能,但您可以在onAfterWrite()方法中编写类似的内容:


更新$many\u many关系需要处理添加和删除的项目,但不需要再次发布页面。
public function onAfterWrite() {
    $this->syncCategories();
}

public function syncCategories() {
    //check if you're in main language, assuminig en_US here
    if ($this->Locale !== 'en_US') return;
    foreach ($this->getTranslations() as $translatedPage) {
        //sync relations here
        $translatedPage->RelationName = $this->RelationName;
        //maybe more fine grained locic for only publishing when translated page is alredy published
        $translatedPage->doPublish(); //writes and publishes in one
    }
}