菜单

ThinkPHP 模板中不能循环一些内容

2019年7月14日 - 计算机教程

$this->_link = array( 'NavigationUrl'=>array( 'mapping_type'=>HAS_MANY, 'class_name' =>'NavigationUrl', 'foreign_key'=>'cateid', 'condition'=> "uid=$a", ), 'Navicate'=>array( 'mapping_type'=>HAS_MANY, 'class_name' =>'NavigationUrl', 'foreign_key'=>'cateid', 'condition'=> "catetop=1", ), );
其实 关联的都是一个表 但是确写了两个数组
目的是返回的数组中返回两个二维数组 分别为 [“NavigationUrl”]
[“Navicate”] [1] => array(4) { [“id”] => string(1) “2”
[“catename”] => string(6) “影视” [“NavigationUrl”] => array(4)
{ [0] => array(9) { [“url_id”] => string(1) “9” [“webname”]
=> string(6) “优酷” [“url”] => string(20) “http://www.youku.com
[“cateid”] => string(1) “2” [“uid”] => string(2) “23”
[“time”] => string(10) “1349596263” [“hots”] => string(1) “0”
[“top”] => string(1) “0” [“catetop”] => string(1) “1” } [1]
=> array(9) { [“url_id”] => string(2) “10” [“webname”] =>
string(6) “酷六” [“url”] => string(18) “http://www.ku6.com
[“cateid”] => string(1) “2” [“uid”] => string(2) “23”
[“time”] => string(10) “1349596281” [“hots”] => string(1) “0”
[“top”] => string(1) “0” [“catetop”] => string(1) “0” } [2]
=> array(9) { [“url_id”] => string(2) “12” [“webname”] =>
string(7) “youtube” [“url”] => string(22) “http://www.youtube.com
[“cateid”] => string(1) “2” [“uid”] => string(2) “23”
[“time”] => string(10) “1349596316” [“hots”] => string(1) “0”
[“top”] => string(1) “1” [“catetop”] => string(1) “0” } [3]
=> array(9) { [“url_id”] => string(2) “16” [“webname”] =>
string(9) “爱奇异” [“url”] => string(16) “http://qqiyi.vom
[“cateid”] => string(1) “2” [“uid”] => string(2) “23”
[“time”] => string(10) “1349667378” [“hots”] => string(1) “0”
[“top”] => string(1) “0” [“catetop”] => string(1) “0” } }
[“Navicate”] => array(1) { [0] => array(9) { [“url_id”]
=> string(1) “9” [“webname”] => string(6) “优酷” [“url”] =>
string(20) “http://www.youku.com” [“cateid”] => string(1) “2”
[“uid”] => string(2) “23” [“time”] => string(10) “1349596263”
[“hots”] => string(1) “0” [“top”] => string(1) “0”
[“catetop”] => string(1) “1” } } }

在这里我们要注意,返回单条结果的方法有find、getBy等方法,下面以官方例子为基础给出演示结果。
可以循环的数组结构


 代码如下

array(2) {
[0] => array(8) {
[“id”] => string(2) “33″
[“title”] => string(6) “222111″
[“content”] => string(6) “222111″
[“user_id”] => string(1) “0″
[“create_time”] => string(10) “1342800330″
[“update_time”] => string(1) “0″
[“status”] => string(1) “1″
[“email”] => string(12) “222111@1.com”
}
[1] => array(8) {
[“id”] => string(2) “32″
[“title”] => string(6) “654364″
[“content”] => string(5) “adlkf”
[“user_id”] => string(1) “0″
[“create_time”] => string(10) “1342800285″
[“update_time”] => string(1) “0″
[“status”] => string(1) “1″
[“email”] => string(9) “222@1.com”
}
}
不可以循环的一维数组
array(8) {
[“id”] => string(2) “10″
[“title”] => string(1) “6″
[“content”] => string(1) “6″
[“user_id”] => string(1) “0″
[“create_time”] => string(10) “1342627991″
[“update_time”] => string(1) “0″
[“status”] => string(1) “1″
[“email”] => string(7) “1@1.com”
}

后记
date:2012-Oct-9th
如果想要将变量转换为 ThinkPHP 可循环,
从原理来讲,
只要将一维数组转换成为二维数组即可,
下面简单写一下步骤

 代码如下

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图