从sfDoctrinePager对象检索原则数据! [英] Retrieving doctrine data from sfDoctrinePager object !
问题描述
在从教义寻呼机对象检索数据时,我正面临一些问题!
让我在下面描述:
I am facing some issues while retrieving data from a doctrine pager object! Let me describe it below:
这是我的寻呼机查询:
$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和Profile数据,如下所示:
Now in my Template I can retrieve my sfGuardUser and Profile data like this:
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
}
但是我仍然无法检索群组& 许可Vendors 数据使用 $ data-> Groups-> name
或 $ data-> LicensedVendors-> status
!它不显示任何错误或任何价值!看起来像是输出一个空字符串。不应该像资料数据那样获得价值?
But I am still unable to retrieve the Groups & LicensedVendors data using $data->Groups->name
or $data->LicensedVendors->status
! It does not show any error or any value either! looks like it outputs an empty string. Shouldn't it get the value just like Profile data ?
但是,当我水合物
时,通过设置:
However, when I hydrate
the query by setting:
$ q-> setHydrationMode(Doctrine_Core :: HYDRATE_SCALAR);
我可以检索所有数据:$ p
$ b
I can retrieve all data through:
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 **
?在将组和许可证表数据作为对象检索到哪里?
How to get those data without setting **Doctrine_Core::HYDRATE_SCALAR**
? Where I'm doing wrong for retrieving those Groups and License table data as an object?
以下是上述表格的模式定义:
Here is the schema definition of the tables described above:
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:
ClientUser:
class: sfGuardUser
local: client_id
foreign: id
foreignAlias: LicensedVendors
onDelete: cascade
foreignType: many
owningSide: true
VendorUser:
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
推荐答案
您可以尝试使用ArrayAccess。
You can try using the ArrayAccess.
意思
foreach ($pager->getResults() as $data) {
echo $data['username'] ; //outputs 'username' from sfGuardUser table
echo '<br />' ;
echo $data['Profile'][0]['org_name'] ; //outputs 'Organization name' from sfGuardUserProfile table
或者也许问题是缺少[0]你的代码,意思是
Or maybe the problem is the lacking [0] in your code, meaning
echo $data->Profile[0]->org_name ; //outputs 'Organization name' from sfGuardUserProfile table
这篇关于从sfDoctrinePager对象检索原则数据!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!