[英]Do not know how to retrieve information with RightJoin on CakePHP 3.2
在一個控制器中的兩個表之間右聯接。 我正在嘗試檢索信息,但無法
$query = $this->Schedules->find('all')
->rightJoin(['Sessions'=> 'sessions'], ['Sessions.id is not null'])
->select(['Sessions.specialist_id'])
->where(['Sessions.id ='=>$session])
foreach ($query as $sp) {
if(!empty($sp)){
$specialist=$sp->Sessions->specialist_id;
獲取專家ID
我無法獲得專家證件
1我已經嘗試過$specialist=$sp->specialist_id;
並沒有任何反應
2使用debug ($sp);die();
這就是我得到的
object(App\Model\Entity\Schedule) {
'Sessions' => [
'specialist_id' => 'a7f6d5b2-b0f3-4a55-b6ce-41d393e80d12'
],
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Schedules'
}
specialist_id
屬於Sessions
,因此您需要通過該密鑰訪問它,即
$sp->Sessions['specialist_id']
要么
$sp['Sessions']['specialist_id']
甚至
$sp->get('Sessions')['specialist_id']
...哦,一旦該功能成為核心
$sp->get('Sessions.specialist_id')
這是相當基礎的東西,但是文檔可能會受益於有關如何訪問嵌套數據的示例,其中包括對象和數組的混合。
附帶說明一下,AFAICT $sp
永遠不應為空,無論結果是沒有。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.