Cakephp 3-如何使用find查询通过实体的转换来查找实体
我有一个带有翻译行为的“页面”模型。我想用CakePHP 3.x搜索与另一种语言匹配的页面Cakephp 3-如何使用find查询通过实体的转换来查找实体,php,cakephp-3.x,Php,Cakephp 3.x,我有一个带有翻译行为的“页面”模型。我想用CakePHP 3.x搜索与另一种语言匹配的页面 class PagesTable extends Table { public function initialize(array $config) { $this->addBehavior('Translate', ['fields' => ['title', 'slug']]); } } 在进行类似搜索之前,我已在控制器中设置了i18n语言环境
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();
}
}
但遗憾的是,我无法获得我想要的唱片。有没有办法做到这一点 我认为findBySlug()函数不能用于这种情况,因为在pages表中没有该字段
你应该这样做:
public function view( $slug = '' )
{
I18n::locale('nl_NL');
$this->Pages->find()
->where( ['Pages_slug_translation.content' => $slug] )
->firstOrFail();
}
可能重复的