Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/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
Cakephp 3-如何使用find查询通过实体的转换来查找实体_Php_Cakephp 3.x - Fatal编程技术网

Cakephp 3-如何使用find查询通过实体的转换来查找实体

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语言环境

我有一个带有翻译行为的“页面”模型。我想用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();
     }
 }
但遗憾的是,我无法获得我想要的唱片。有没有办法做到这一点

我认为findBySlug()函数不能用于这种情况,因为在pages表中没有该字段

你应该这样做:

public function view( $slug = '' )
     {
         I18n::locale('nl_NL');
         $this->Pages->find()
               ->where( ['Pages_slug_translation.content' => $slug] )
               ->firstOrFail();
     }
可能重复的