Yii学习(7)----使用with关系
2013-12-04 13:44
453 查看
首先在model里面定义一个relations关系,如下:
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'fishcenter'=>array(self::BELONGS_TO,'FishCenter','fcid'),
//'typeid'=>array(self::BELONGS_TO,'CommonClass','id'),
);
}
这里的关系被命名为fishcenter,下面我们在controller中使用这样的关系,
$new = Pond::model()->with(array(
'fishcenter'=>array('fcid','address','fcname'),
))->findAll(array(
'select'=>array('pondid','pondname','address','price'),
'order'=>'pondid DESC',
'limit'=>10,
));这样获得的数据就是这样的结构:
$new=array(
'pondid'=>'',
'pondname'=>'',
......
fishcenter=>array(
'fcid'=>'',
'address'=>'',
......
)
);
所以说如果要获取fcid的数据,必须是:$new['fishcenter']['fcid']的形式。
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'fishcenter'=>array(self::BELONGS_TO,'FishCenter','fcid'),
//'typeid'=>array(self::BELONGS_TO,'CommonClass','id'),
);
}
这里的关系被命名为fishcenter,下面我们在controller中使用这样的关系,
$new = Pond::model()->with(array(
'fishcenter'=>array('fcid','address','fcname'),
))->findAll(array(
'select'=>array('pondid','pondname','address','price'),
'order'=>'pondid DESC',
'limit'=>10,
));这样获得的数据就是这样的结构:
$new=array(
'pondid'=>'',
'pondname'=>'',
......
fishcenter=>array(
'fcid'=>'',
'address'=>'',
......
)
);
所以说如果要获取fcid的数据,必须是:$new['fishcenter']['fcid']的形式。
相关文章推荐
- Yii学习(8)----with中使用多重关系调用
- YII Framework学习教程-YII的Model-数据库操作2-多关系的CActiveRecord使用举例
- 【学习】flex中with关键字的使用
- 学习《Building Applications with FME Objects》 之十 使用集合
- YII Framework学习教程-YII的Model-数据库操作4-Query Builder使用举例
- yii学习过程(常用组件的使用)
- YII Framework学习教程-YII的Model-基本规则和使用-2011-11-22
- EF学习杂记38:如何使用CodeOnly with Astoria
- 基于投影学习的负采样改进型上位词关系提取 (翻译学习使用)
- Yii学习(4)----Gii的使用
- Objective-C 学习笔记之使用跨文件依赖关系
- YII Framework学习教程-YII的V-view的深入了解和使用-2011-11-16
- Spring学习笔记之使用对象-关系映射持久化数据
- 关于后盾网yii框架的学习小结(5)--验证码的使用与规则的设置,为后台模块设置独立的布局
- Entity Framework with MySQL 学习笔记一(关系)
- yii学习过程(常用组件的使用)
- 关于后盾网yii框架的学习小结(10)--使用AR类的增删改查
- Agile Web Application Development with Yii 1.1 and PHP5 读后总结(2)初步使用
- 关于后盾网yii框架的学习小结(7)--session的使用和redirect等的方法的使用
- 关于我学习Yii框架 - 数据库relation的使用