Yii 框架:这行 JQuery 代码是什么意思

2022-01-04 00:00:00 search jquery php yii
<块引用>

可能的重复:

  • http://code.google.com/p/zii/source/browse/trunk/widgets/assets/gridview/jquery.yiigridview.js?r=65
  • http://www.yiiframework.com/doc/api/1.1/CGridView
  • 抱歉,我对Yii框架不太了解,祝你好运!

    Possible Duplicate:
    Yii framework: Using data from related Active Record models for searching

    Yii provide advanced search functionality under admin page.

    This picture explain my question well.

    This functionality shown on the picture is carried out by following code sample.

    $('.search-form form').submit(function(){
        $.fn.yiiGridView.update('order-grid', {
            data: $(this).serialize()
        });
        return false;
    });
    

    There is a form with class attribute named search-form where we provide search criteria. Based on the search criteria, it update the grid view called order which is generated by following code sample.

    <?php $this->widget('zii.widgets.grid.CGridView', array(
        'id'=>'order-grid',
        'dataProvider'=>$model->search(),
        'columns'=>array(
            'id',
            'order_create_date',
            'price',
            'bank_account_number',
            'hardwaredetail_Id',
            'user_id',
            'user.name',
            'user.email',
            ),
    } 
    

    Order table has a relationship with user table. i want to perform search functionality on user's name and email address. But Advanced search functionality Auto generate code only for search on order table. i am trying to customize advanced search to be able to search on relational data as well

    Thanks in advance for any help

    解决方案

    I'm not super sure what you're asking or if it's possible, but let me try and explain what is going on in your current code eample:

    $('.search-form form').submit(function(){
        $.fn.yiiGridView.update('order-grid', {
             data: $(this).serialize()
        });
        return false;
    });
    

    1. When you submit the form by hitting the search button jQuery stops the form from submitting.
    2. Instead, it will submit it using the $.fn.yiiGridView.update function.
    3. $(this).serialize() takes all of the data from the form and puts it into a format that's easy for the server to read.

    As for the other code sample it just creates the HTML for the form with an id of 'order-grid'.

    Now, on to what you're hoping to do instead. I've looked for some examples and docs about the $.fn.yiiGridView.update, which might be able to shed light on this. Here's what I've got:

    1. http://tech.ldg.me/yii-php-framework-snippets
    2. http://code.google.com/p/zii/source/browse/trunk/widgets/assets/gridview/jquery.yiigridview.js?r=65
    3. http://www.yiiframework.com/doc/api/1.1/CGridView

    Sorry, I don't know more about the Yii framework and good luck!

    相关文章