首页 文章

使用$ _GET和URL进行搜索

提问于
浏览
2

我'm trying to filter data in my view based on URL parameters. I'目前在我的视图中使用基本的Yii Ajax搜索,它使用 $_POST 来获得结果以显示在 CGridView 中 .

我的模型中的 search() 方法也是默认方法,使用 CDbCriteriacompare() 根据通过视图中提到的搜索提交的条件返回 CActiveDataProvider .

这里的盛大 question 是:

如何通过URL进行搜索,看起来像 http://example.com/index.php/something/listAll?id=10&owner=numline1

谢谢!

1 回答

  • 1

    经过一些调试解决了它 . 事实证明,我在控制器中需要这样的东西:

    if(isset($_GET['Book']))
        $model->attributes=$_GET['Book'];
    else if(isset($_POST['Book']))
        $model->attributes=$_POST['Book'];
    

    实际的搜索网址将如下所示:

    http://example.com/index.php/books/listAll?Book[id]=1234&Book[name]=Lorem%20Ipsum
    

相关问题