《应用Yii1.1和PHP5进行敏捷Web开发》第6章问题 [ 新手入门 ]
Hi,
我是Yii的初学者,在学习链接教材 http://yiibook.com/book/agile_web_application_development_with_yii1.1_and_php5/chapter-6 第六章(英文版121页)时遇见问题,请问下面的代码怎样使用,应该写在哪个文件哪个function里面?
.................... 有了这些,我们可以相当简单的访问所有的与项目(Project)关联的问题(Issue)和/或用户:
//create the Project model instance by primary key:
$model = Project::model()->findbyPk(1);
//get an array of all associated Issue AR instances
$allIssues = $model->issues;
//get an array of all associated User AR instance
$allUsers = $model->users;
//get the User AR instance representing the owner of
//the first issue associated with this project
$ownerOfFirstIssue = $model->issues[0]->owner;
通常我们需要写复杂的SQL join语句来访问这样的关系型数据。而使用了Yii中的关系型AR,将我们从这种复杂漫长痛苦的过程中解放出来。我们现在可以使用优雅精简的面向对象语法来访问这些关系了...................
共 1 条回复
TimKan 湖南
注册时间:2012-09-05
最后登录:1970-01-01
在线时长:0小时0分
最后登录:1970-01-01
在线时长:0小时0分
- 粉丝0
- 金钱45
- 威望0
- 积分45