【问题标题】:YII search is not working when renderPartial from another page来自另一个页面的 renderPartial 时 YII 搜索不起作用
【发布时间】:2013-02-27 02:04:02
【问题描述】:

我在使用 Yii 搜索时遇到问题,直接访问页面(学生/管理员)时它工作正常,但如果我从另一个页面(学生/注册)部分渲染同一页面,Yii 过滤器不会搜索结果..

提前致谢

【问题讨论】:

  • CGridView 中的 Yii 搜索不起作用

标签: php search filter yii cgridview


【解决方案1】:

您必须在actionRegStudentsController 中手动创建模型。 CGridView 将使用模型的这些值来设置过滤器。

这可能是这样的:

public function actionReg($id) {
  $model = Students::model();
  $model->attributes = $_GET['Students'];

  $this->render('reg', array(
           'model' => $model,
        ));
}

如果模型中有自定义值,则还必须设置它们,例如

  $model->calculatedAverage = $_GET['Students']['calculatedAverage'];

然后在您的RegView 中,您可以将此模型传递给表格。

要了解其工作原理,请尝试了解 adminAction 方法中发生的情况。

【讨论】:

  • Thnx Man,它对我有用.. 我需要了解更多..thanx 很多
【解决方案2】:

如果我做对了,如果你没有正确使用它,renderPartial 不会处理内联 js。尝试做:

$this->renderPartial('view',array(...),false,true);

应该有帮助。最后一个参数 (true) 告诉 Yii 处理输出。

【讨论】:

  • thx alot kapo,我的 renderPartial 代码,在这里给出.. 我在 CGridview 中使用它.. 页面显示数据和其他功能运行良好。除了搜索 array('id' => 'tab1','label'=>'Manage', 'content'=>$this->renderPartial('//Students/admin', array('model'=>$model ,), true ), 'active' => true,),
  • 我不明白你在哪里使用这个数组('id'=>...)。在控制器中?如果没有看到一些更大的代码,我无法帮助你
  • $tabs=array(array('id'=>'tab1','label'=>'Manage', 'content'=>$this->renderPartial('//Students/admin ', array('model'=>$model,), true, true ), 'active' => true,), array('id'=>'tab4','label'=>'添加学生', ' content'=>$this->renderPartial('create',array('model'=>$model,'medicalinfo'=>$medicalinfo,'parent'=>$parent,'royalty'=>$royalty,'worksheet '=>$worksheet), true)), array('id'=>'tab3','label'=>'2012', 'content'=>$this->renderPartial('adminold', array('model '=>$model1,), true)),); $this->widget('bootstrap.widgets.TbTabs', array( 'type'=>'pills', 'id' => 'tabs', 'tabs'=> $tabs,
  • 我在'bootstrap.widgets.TbTabs'下使用这个
  • 这里的人有和你类似的问题:yiiframework.ru/forum/viewtopic.php?f=3&t=8275 是俄语,但他所做的是使用 renderPartial(...,false,true);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-27
  • 1970-01-01
  • 2021-07-07
  • 1970-01-01
相关资源
最近更新 更多