【发布时间】:2023-04-03 00:34:01
【问题描述】:
我有一个带有翻译行为的“页面”模型。我想用 CakePHP 3.x 搜索与另一种语言匹配的页面。
class PagesTable extends Table
{
public function initialize(array $config)
{
$this->addBehavior('Translate', ['fields' => ['title', 'slug']]);
}
}
在搜索之前,我已经在控制器中设置了 i18n 语言环境:
class PagesController extends AppController
{
/**
* View method
*/
public function view( $slug = '' )
{
I18n::locale('nl_NL');
$this->Pages->findBySlug("foobar-in-nl")->first();
}
}
但很遗憾,我不会得到我想要的唱片。有没有办法做到这一点?
【问题讨论】:
标签: php cakephp-3.x