yii中从多个表中获取数据
我有 2 个表
AutoScriptArgumentClass
id
ScriptArgumentClass
AutoTestScriptMeta
id
AutoTestScript_id
这里的ScriptArgumentClass_id
是我的查询。
select sac.id,sac.ScriptArgumentClassType
from AutoScriptArgumentClass sac,AutoTestScriptMeta tsm
where tsm.ScriptArgumentClass_id = sac.id
and tsm.AutoTestScript_id=129
我如何在 yii 中写这个
我想以这种方式:
**$data=AutoTestScript::model()->findAll('Category_id=:parent_id',
array(':parent_id'=>(int) $_POST['TestCaseCategory']));**
$data=CHtml::listData($data,'id','ScriptName');
foreach($data as $value=>$name)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}
谢谢
I have 2 tables
AutoScriptArgumentClass
id
ScriptArgumentClass
AutoTestScriptMeta
id
AutoTestScript_id
ScriptArgumentClass_id
here is my query.
select sac.id,sac.ScriptArgumentClassType
from AutoScriptArgumentClass sac,AutoTestScriptMeta tsm
where tsm.ScriptArgumentClass_id = sac.id
and tsm.AutoTestScript_id=129
how do I write this in yii
I would like to have in this manner:
**$data=AutoTestScript::model()->findAll('Category_id=:parent_id',
array(':parent_id'=>(int) $_POST['TestCaseCategory']));**
$data=CHtml::listData($data,'id','ScriptName');
foreach($data as $value=>$name)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
恐怕这是不可能的,因为您正在尝试将多个表中的数据获取到特定表的 CActiveRecordModel 实例中。
该模型没有其他表的列的实例,因此它不能为您所用。
谢谢。
I am afraid this will not be possible, as you are trying to get the data from multiple table into an instance of a CActiveRecordModel of a particular table.
This model does not have the instances of the columns of the other table, hence it cannot not avail them to you.
Thanks.
在两种情况下是可能的。首先,您在控制器中编写一个函数,其中包含正确的查询并从 cgrid 视图调用该函数,或者您可以更有效地检查页面
http://www.yiiframework。 com/wiki/281/searching-and-sorting-by-lated-model-in-cgridview/
确保表保持相关性。如果您的表是 MYISAM 格式,请将其更改为 INODB 并尝试..希望它对您有用
Its possible in two condition. first you write a function in in your controller which contain the proper query and call the function from cgrid view or you can check the page more efficient way
http://www.yiiframework.com/wiki/281/searching-and-sorting-by-related-model-in-cgridview/
make sure the tables maintain the reletaionship. if your tables are in MYISAM format change it into INODB and try.. hope its works for you