gpt4 book ai didi

cakephp - Cakephp 翻译行为的默认行为不起作用

转载 作者:行者123 更新时间:2023-12-04 06:14:44 29 4
gpt4 key购买 nike

任何人都可以告诉我为什么当一个字段没有翻译时它返回空,而不是默认翻译?

我会感谢所有建议...

不知道你想看我代码的哪一部分,因为它都是直接来自 www.book.cake.org。所以我粘贴了一些代码:

型号定义:

<?php
class Article extends AppModel
{
var $useTable = 'nc_articles';
var $name = 'Article';
var $actsAs = array(
'Translate' => array(
'title', 'content', 'meta_key_words','meta_description'
)
);
// Use a different model
var $translateModel = 'ArticlesI18n';
// Use a different table for translateModel
var $translateTable = 'nc_articles_i18ns';
var $belongsTo = array(
'Author' => array('className' => 'User',
'foreignKey' => 'author_id',
'conditions' => '',
'fields' => array(),
'order' => '',
'counterCache' => ''),
'Modifier' => array('className' => 'User',
'foreignKey' => 'modifier_id',
'conditions' => '',
'fields' => array(),
'order' => '',
'counterCache' => ''),
'Category' => array('className' => 'ArticlesCategory',
'foreignKey' => 'category_id',
'conditions' => '',
'fields' => array(),
'order' => '',
'counterCache' => ''),
'Layout' => array('className' => 'Layout',
'foreignKey' => 'layout_id',
'conditions' => '',
'fields' => array(),
'order' => '',
'counterCache' => ''),
);
var $hasMany = array(
'Comments' => array(
'className' => 'ArticlesComment',
'foreignKey' => 'article_id',
'conditions' => array(),
'order' => '',
'limit' => '',
//'dependent'=> true When dependent is set to true, recursive model deletion is possible. In this example, Comment records will be deleted when their associated User record has been deleted.
)
);


}
?>

然后是我更改语言的功能:
function setLanguage($languageCode='pol')
{
$this->Session->write('Config.language', $languageCode);
$this->redirect($this->referer());
}

你想看更多吗?

最佳答案

让我回答我自己的问题。我不得不写更多的东西。首先,我必须在 core.php 中声明我的 Config.language 然后对于每个被翻译的模型我必须声明一个局部变量,它是一个语言代码数组

$this->Article->array('en','pol');

这就是我解决问题的方式。但是现在翻译查询很长,我面临着优化问题。

关于cakephp - Cakephp 翻译行为的默认行为不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7400929/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com