cakephp数组结果[达到最大深度] [英] cakephp array results [maximum depth reached]
问题描述
我有两个模型。通过 HABTM 加入的教师和主题定义了两种方法。教师可以教授许多科目,并且许多教师可以教授科目。加入表是 subjects_teachers ,并且具有字段 id,teacher_id和subject_id。
从其模型中获取教师数据,我希望所有教师及其各自的科目,
从其模型中获取主题数据我希望也能看到教师教学那两个实例上的特定主体
问题
,关联模型返回正确的记录数,但缺少数据。我显示相应的数组时看到 [达到的最大深度] 。
我 加入表,并且仅修复教师模型。主题模型仍然有问题。
知道什么是[达到的最大深度],以及为什么从连接表中删除id字段以固定教师问题,而不是主题。
如果它的重要我应该提到我的教师模型主键字段不遵循惯例
SUBJECT模型
public $ hasAndBelongsToMany = array(
'Teacher'=> array(
'className'=>'Teacher',
'joinTable'= >'subjects_teachers',
'foreignKey'=>'subject_id',
'associationForeignKey'=>'teacher_id',
'unique'=>'keepExisting'
)
)
教师模式
public $ hasAndBelongsToMany = array(
'Subject'=> array(
'className'=>'Subject',
'joinTable '=>'subjects_teachers',
'foreignKey'=>'teacher_id',
'associationForeignKey'=>'subject_id',
'unique'=>'keepExisting'
)
);
来自主题的结果
array(
(int)0 => array(
'Subject'=> array(
'id' '1',
'subject_code'=>'121',
'subject_name'=>'数学',
'compulsory'=> true
),
'Teacher'=> array(
(int)0 => array(
[达到最大深度]
),
(int)数组(
[达到最大深度]
),
(int)2 =>数组(
[达到最大深度]
)
) b $ b),
来自Teacher before removin id字段的结果 p>
array(
'Teacher'=> array(
'teacher_id'=>'6'
'first_name'=>'George',
),
'Subject'=> array(
(int)0 = id'=>'1',
'subject_code'=> '121',
'subject_name'=> 'Mathematics',
'compulsory'=> true,
'SubjectsTeacher'=>数组(
[达到最大深度]
)
)
移除ID字段后的结果
'Subject'=> array(
(int)0 => array(
'id'=>'1',
'subject_code'=>'121',
' =>'数学',
'compulsory'=> true
),
25
)或 Debugger :: dump()/ exportVar()
具有足够深入嵌套数据的深度(第二个参数,默认为 3
)。 另请参阅
- http://book.cakephp.org/2.0/en/development/debugging.html
- < a href =http://api.cakephp.org/2.5/class-Debugger.html =nofollow> http://api.cakephp.org/2.5/class-Debugger.html
i have two models. Teacher and Subject joined by HABTM defined both ways. A teacher can teach many subjects and a subject can be taught by many teachers.my join table is subjects_teachers and have fields id,teacher_id and subject_id.
Fetching Teacher data from its model, i expect all teachers and their respective subjects , Fetching Subject data from its model i expect to also see the teachers teaching that particular subject
problem on both instances, the associated model returns the correct number of records but the data is absent. i see [maximum depth reached] when i display the respective arrays.
I removed the id field from the join table and that fixed only the Teacher model.The Subject model still has the problem.
i just need to know what [maximum depth reached] means and why removing the id filed from the join table fixed the Teacher problem but not Subject.
also if its important i should mention that my Teacher model primary key field doesnt follow convention SUBJECT model
public $hasAndBelongsToMany = array(
'Teacher' => array(
'className' => 'Teacher',
'joinTable' => 'subjects_teachers',
'foreignKey' => 'subject_id',
'associationForeignKey' => 'teacher_id',
'unique' => 'keepExisting'
)
);
Teacher Model
public $hasAndBelongsToMany = array(
'Subject' => array(
'className' => 'Subject',
'joinTable' => 'subjects_teachers',
'foreignKey' => 'teacher_id',
'associationForeignKey' => 'subject_id',
'unique' => 'keepExisting'
)
);
Results from subject
array(
(int) 0 => array(
'Subject' => array(
'id' => '1',
'subject_code' => '121',
'subject_name' => 'Mathematics',
'compulsory' => true
),
'Teacher' => array(
(int) 0 => array(
[maximum depth reached]
),
(int) 1 => array(
[maximum depth reached]
),
(int) 2 => array(
[maximum depth reached]
)
)
),
Results from Teacher before removin id field
array(
'Teacher' => array(
'teacher_id' => '6',
'first_name' => 'George',
),
'Subject' => array(
(int) 0 => array(
'id' => '1',
'subject_code' => '121',
'subject_name' => 'Mathematics',
'compulsory' => true,
'SubjectsTeacher' => array(
[maximum depth reached]
)
)
Results after removing id field
'Subject' => array(
(int) 0 => array(
'id' => '1',
'subject_code' => '121',
'subject_name' => 'Mathematics',
'compulsory' => true
),
Your data exists, the debugger just wont display it because the depth
option limits it. Use debug()
(default depth = 25
) or Debugger::dump()/exportVar()
with a depth (second argument, defaults to 3
) high enough for your deeply nested data.
See also
- http://book.cakephp.org/2.0/en/development/debugging.html
- http://api.cakephp.org/2.5/class-Debugger.html
这篇关于cakephp数组结果[达到最大深度]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!