这个thinkphp多维数组如何输出,模板如何写
cmpany模型/**/'Raty'=>array('mapping_type'=>HAS_ONE,'class_name'=>Raty,'foreign_key'=>'...
cmpany模型
/**/
'Raty' =>array(
'mapping_type' =>HAS_ONE,
'class_name' =>Raty,
'foreign_key'=>'company_id',
'as_fields'=>'work_voter,work_total,accommodation_voter,accommodation_total,dining_voter,dining_total,life_voter,life_total'
),
'Comment'=>array(
'mapping_type' =>HAS_MANY,
'class_name' =>Comment,
'mapping_name'=>'Comment',
'foreign_key'=>'company_id',
'as_fields'=>'updatetime,ip,rate_work,rate_accommodation,rate_dining,rate_life,wage,content,status'
),
);
控制器
$Company = D('Company');
$where['company_code']=$code;
$company = $Company->relation(true)->where($where)->find();
$this->assign('company',$company);// 赋值数据集
$this->display(comment);
dump($company);输出结果
array(20) {
["company_ID"] => string(1) "1"
["company_code"] => string(13) "15181be9c8057"
["city_id"] => string(4) "3521"
["industrial_id"] => string(1) "0"
["company_name"] => string(9) "万大达"
["address"] => string(0) ""
["FFE"] => string(1) "0"
["trade"] => string(0) ""
["company_tel"] => string(0) ""
["Comment"] => array(4) {
[0] => array(12) {
["comment_id"] => string(1) "7"
["user_id"] => string(1) "0"
["company_id"] => string(1) "1"
["updatetime"] => string(1) "0"
["ip"] => string(0) ""
["content"] => string(18) "认识法国如果"
["status"] => string(1) "0"
}
[1] => array(12) { }
[2] => array(12) {}
[3] => array(12) {}
请问我如何输出: ["content"] => string(18) "认识法国如果"
因为留言很多的,所以要循环输出: ["content"] =
<volist name="company" id="vo">
<div>{$vo.Comment.content}</div>
</volist> 展开
/**/
'Raty' =>array(
'mapping_type' =>HAS_ONE,
'class_name' =>Raty,
'foreign_key'=>'company_id',
'as_fields'=>'work_voter,work_total,accommodation_voter,accommodation_total,dining_voter,dining_total,life_voter,life_total'
),
'Comment'=>array(
'mapping_type' =>HAS_MANY,
'class_name' =>Comment,
'mapping_name'=>'Comment',
'foreign_key'=>'company_id',
'as_fields'=>'updatetime,ip,rate_work,rate_accommodation,rate_dining,rate_life,wage,content,status'
),
);
控制器
$Company = D('Company');
$where['company_code']=$code;
$company = $Company->relation(true)->where($where)->find();
$this->assign('company',$company);// 赋值数据集
$this->display(comment);
dump($company);输出结果
array(20) {
["company_ID"] => string(1) "1"
["company_code"] => string(13) "15181be9c8057"
["city_id"] => string(4) "3521"
["industrial_id"] => string(1) "0"
["company_name"] => string(9) "万大达"
["address"] => string(0) ""
["FFE"] => string(1) "0"
["trade"] => string(0) ""
["company_tel"] => string(0) ""
["Comment"] => array(4) {
[0] => array(12) {
["comment_id"] => string(1) "7"
["user_id"] => string(1) "0"
["company_id"] => string(1) "1"
["updatetime"] => string(1) "0"
["ip"] => string(0) ""
["content"] => string(18) "认识法国如果"
["status"] => string(1) "0"
}
[1] => array(12) { }
[2] => array(12) {}
[3] => array(12) {}
请问我如何输出: ["content"] => string(18) "认识法国如果"
因为留言很多的,所以要循环输出: ["content"] =
<volist name="company" id="vo">
<div>{$vo.Comment.content}</div>
</volist> 展开
展开全部
<volist name="company" id="vo">
{$vo.company_name}
<volist name="vo['Comment']" id="sub">
{$sub.content}
</volist>
</volist>
如上,可嵌套循环
{$vo.company_name}
<volist name="vo['Comment']" id="sub">
{$sub.content}
</volist>
</volist>
如上,可嵌套循环
追问
这个回答适合用select ( )返回的数组。
我的是find( )返回的数组,我自己解决了。
{$vo.content}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询