我使用主义查询构建器创建了这个查询,我得到的返回是一个数组的数组。我想获得一个对象数组的返回值,这可能吗?
我知道 Doctrine 通常返回实体的对象,因为我有一个内部联接来从另一个表中获取名称,它返回数组。
提前致谢。
$qb->select('u', 'h.name')
->from('AppBundle:UserHose', 'u')
->innerJoin('AppBundle:Hose', 'h', 'WITH', 'u.hoseId = h.id')
->where('u.userId = :userId')
->orderBy('u.id', 'DESC')
->setParameter('userId', $userId);
return $qb->getQuery()->getResult();
Run Code Online (Sandbox Code Playgroud) 我正在尝试向正在获取资源类型文件的函数添加返回类型,但我无法弄清楚要添加什么返回类型?我收到一个错误,我的返回是一个资源,并且应该是一个资源,这让我很困惑:P
这是我的函数(此函数中发生了更多事情来创建文件路径,但我将其省略,因为它不相关。
private function getMappingExportFile(JobParameters $jobParameters): \resource
{
return fopen($filePath,"r");
}
Run Code Online (Sandbox Code Playgroud)
这是我收到的错误
::getMappingExportFile() must be an instance of resource, resource returned
Run Code Online (Sandbox Code Playgroud)
如果删除返回类型,一切都会正常,但我更喜欢使我的代码更加严格。
如何获取打字稿中的区域设置?
这是在我的控制器中:
$form = $this->createForm(new ConfiguratorClientType(), $configuratorClient);
Run Code Online (Sandbox Code Playgroud)
我的表单生成器中有这个:
->add('language',
EntityType::class,
array(
'class' => 'CommonBundle:Language',
'choice_label' => function ($language) {
return $language->getName()[$locale];
},
'attr' => array(
'class' => 'form-control'
)
)
)
Run Code Online (Sandbox Code Playgroud)
但我不知道如何获取那里的语言环境。
php ×2
symfony ×2
doctrine-orm ×1
file ×1
forms ×1
function ×1
locale ×1
object ×1
return-type ×1
symfony-2.8 ×1