내 쿼리가 두 개 이상의 테이블에서 여러 열을 선택하는 동안 Doctrine_Pager 또는 sfDoctrinePager를 사용하여 페이지 매김을 구현하는 방법은 무엇입니까?doctrine 또는 symfony 호출기를 여러 테이블에서 선택된 다른 열과 함께 사용하는 방법은 무엇입니까?
EDIT1 :
좋아, 지금 나는 나단이 아래에 설명 어떻게 수행 할 수 있다고 생각! 내가 쿼리에서 특정 데이터를 검색 할 수 없어 혼란스러워! 저 아래에 그것을 설명하자
$pager = new sfDoctrinePager('sfGuardUser', '5');
$q = Doctrine_Query::create()
->select('u.id, u.username, p.org_name, g.name, l.status')
->from('sfGuardUser u')
->leftJoin('u.Profile p')
->leftJoin('u.Groups g')
->leftJoin('u.LicensedVendors l')
->where('g.name = \'client\'');
$pager->setQuery($q);
$pager->setPage($request->getParameter('page', 1));
$pager->init();
나는이처럼 내 sfGuardUser 및 프로필 데이터를 검색 할 수 있습니다 내 템플릿 지금 : 이것은 내 호출기 쿼리
이다 내가 잘못에 노력했다
foreach ($pager->getResults() as $data) {
echo $data->username ; //outputs 'username' from sfGuardUser table
echo '<br />' ;
echo $data->Profile->org_name ; //outputs 'Organization name' from sfGuardUserProfile table
}
이 아닌 $data->Profile->org_name
으로 프로파일 데이터를 검색하십시오! 이제이 부분에 대한 작업이 올바르게 수행되었지만 여전히 문제가 있습니다!
나는 여전히 단체 & LicensedVendors $data->Groups->name
또는 $data->LicensedVendors->status
를 사용하여 데이터를 검색 할 수 없습니다입니다! 어떤 오류나 어떤 값도 보여주지 않습니다! 빈 문자열을 출력하는 것처럼 보입니다. 프로필 데이터처럼 가치를 가져야하지 않습니까? 하지만 설정하여 쿼리를 hydrate
때
foreach ($pager->getResults() as $data) {
echo $data['u_username'];
echo $data['p_org_name'];
echo $data['g_name'];
echo $data['l_status'];
}
방법 **Doctrine_Core::HYDRATE_SCALAR**
을 설정하지 않고 그 데이터를 얻을 :
$q->setHydrationMode(Doctrine_Core::HYDRATE_SCALAR);
을 나는 통해 모든 데이터를 검색 할 수 있습니까? 검색을 잘못했을 때 그룹 및 LicensedVendors 테이블 데이터?
License:
actAs: [Timestampable]
tableName: licenses
columns:
id:
type: integer(4)
primary: true
notnull: true
autoincrement: true
status:
type: enum
values: ['approved','pending_admin','pending_client','pending_vendor','rejected']
default: 'pending'
client_id:
type: integer(8)
notnull: true
vendor_id:
type: integer(8)
notnull: true
product_desc:
type: clob(16777215)
supplier_name:
type: string(80)
other_desc:
type: string(50)
financial_statement:
type: clob
relations:
VendorUser:
class: sfGuardUser
local: client_id
foreign: id
foreignAlias: LicensedVendors
onDelete: cascade
foreignType: many
owningSide: true
ClientUser:
class: sfGuardUser
local: vendor_id
foreign: id
foreignAlias: LicensedClients
onDelete: cascade
foreignType: many
owningSide: true
sfGuardUser:
actAs: [Timestampable]
columns:
first_name: string(255)
last_name: string(255)
email_address:
type: string(255)
notnull: true
unique: true
username:
type: string(128)
notnull: true
unique: true
algorithm:
type: string(128)
default: sha1
notnull: true
salt: string(128)
password: string(128)
is_active:
type: boolean
default: 1
is_super_admin:
type: boolean
default: false
last_login:
type: timestamp
indexes:
is_active_idx:
fields: [is_active]
relations:
Groups:
class: sfGuardGroup
local: user_id
foreign: group_id
refClass: sfGuardUserGroup
foreignAlias: Users
sfGuardUserProfile:
actAs:
Timestampable: ~
columns:
user_id:
type: integer
notnull: true
email:
type: string(80)
notnull: true
unique: true
email_new:
type: string(80)
unique: true
firstname:
type: string(30)
lastname:
type: string(70)
org_name:
type: string(80)
notnull: true
relations:
User:
class: sfGuardUser
foreign: id
local: user_id
type: one
onDelete: cascade
foreignType: one
foreignAlias: Profile
sfGuardGroup:
actAs: [Timestampable]
columns:
name:
type: string(255)
unique: true
description: string(1000)
relations:
Users:
class: sfGuardUser
refClass: sfGuardUserGroup
local: group_id
foreign: user_id
foreignAlias: Groups
Edit2가 : 내가 별도의 질문으로 첫 번째 편집에 설명 된 나의 새로운 문제를 게시 여기
은 위에서 설명 된 테이블의 스키마 정의입니다 here!
답장을 보내 주신 Nathan에게 감사드립니다! 그것은 당신이 위에 두는 방식으로 작동해야합니다; 잠시 후에 문제를 알아 냈습니다. 실제로 다른 방식으로 데이터를 검색해야합니다. 그러나 내가 편집 한 부분에 정교하게 쏟아 부은 이슈가 여전히 남아 있습니다! 당신은 그것을 볼 수 있습니다 :) – med
medhad, 당신의 원래 질문은 분명했고 나는 명확하게 대답하려고했습니다. 편집하면 완전히 다른 것입니다. 어쩌면 새로운 질문을해야 할 것입니다. 호출기를 설정하기 전에 실제로 조인이 필요한지 궁금합니다. 호출기 결과를 반복하면서'$ license-> getVendorUser()'를 할 수 없습니까? – Nathan
Nathan, 새로운 질문으로 게시하는 것이 맞습니다! 방금 새 스레드에서 요청하고 여기에서 긁어 냈습니다! * $ license-> getVendorsUser * true로 사용자 (공급 업체)를 얻을 수 있지만이 경우 클라이언트 그룹에있는 모든 사용자와 현재 공급 업체의 해당 라이센스 상태를 쿼리해야합니다. – med