Передать значение раскрывающегося списка в URI в PHP CodeIgniter - PullRequest
0 голосов
/ 24 октября 2018

Я работаю над CodeIgniter проектом.В моем web-app я фильтрую свой data-tables processing on server, используя drop-down lists с выбором нескольких значений из раскрывающегося списка.Я получаю правильный вывод.

Мой код просмотра:

<div class="content-wrapper">
<div class="box-body">
    <form name="listproperty" action="" method="post" role="form" id="form-filter">
        <div class="row">
            <div class="col-md-3">
                <label>Area: </label>
                <select class="form-control", name="area_name" id="area_name">
                    <option value="0">Select Area</option>
                    <?php 
                        $area_id; 
                        foreach ($areaList as $area) { ?>
                            <option value="<?= $area->area_id_primary; ?>" <?php if ($area->area_id_primary == $area_id) { echo "selected='selected'"; } ?>><?= $area->area_name; ?></option>
                        <?php } ?>
                </select>
            </div>
            <div class="col-md-3">
                <label>City: </label>
                <select class="form-control" name="city_name" id="city_name" multiple="">
                    <option value="">Select City</option>
                    <?php $ct = explode(' ', $city); 
                        foreach ($propertyCityList as $propertyCity) { 
                            $selected = false;
                            foreach ($ct as $usercity) { 
                                if ($usercity == $propertyCity->city_id_primary) {
                                    $selected = true;
                                    break;
                                }
                            } ?>
                            <option value="<?= $propertyCity->city_id_primary; ?>" <?php if($selected === true) { echo "selected='selected'"; } ?>><?= $propertyCity->city_name; ?></option>
                    <?php } ?>
                </select>
            </div>
        </div>
        <div class="row">&nbsp;</div>
        <div class="row">
            <div class="pull-right">
                <div class="col-md-12">
                    <button type="button" id="btn-filter" class="btn btn-success" style="margin-right: 25px;">Filter</button>
                    <button type="button" id="btn-reset" class="btn btn-default">Reset</button>
                </div>
            </div>
        </div>  
    </form>
</div><hr>
<div class="box-body">
    <table class="table table-striped table-bordered" id="listpropertyData" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th width="10%">Added Date</th>
                <th width="10%">ASYS No.</th>
                <th width="18%">Address</th>
                <th width="10%">City</th>
                <th width="15%" style="text-align: center;">Action</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th>Added Date</th>
                <th>ASYS No.</th>
                <th>Address</th>
                <th>City</th>
                <th style="text-align: center;">Action</th>
            </tr>
        </tfoot>
    </table>
</div>

<script type="text/javascript">
    var property;
    $(document).ready(function() {

        $("#area_name").select2();
        $("#city_name").select2();

        property = $('#listpropertyData').DataTable({
            "processing": true,
            "serverSide": true,
            "ajax": {
                "url": "<?= base_url('Controller/getPropertyDatatable'); ?>",
                "type": "POST",
                "dataType": "JSON",
                "data": function ( data ) {
                    data.area_name = $('#area_name').val();
                    data.city_name = $('#city_name').val();
                }
            },
            "dom": '<"top"fli>rt<"bottom"p><"clear">',
            "lengthMenu": [[25, 50, 100, 200, -1], [25, 50, 100, 200, "All"]],
            "columnDefs": [
                {
                    "targets":[7],
                    "orderable":false
                },
            ],
        });

        $('.dataTables_filter input[type="search"]').css(
            {'width':'450px','display':'inline-block'}
        );

        $('#btn-filter').click(function(){ //button filter event click
            property.ajax.reload();  //just reload table
        });
        $('#btn-reset').click(function(){ //button reset event click
            $('#form-filter')[0].reset();
            property.ajax.reload(); 
            window.location.reload(); //just reload table
        });
    });
</script>

Мой код контроллера:

public function listProperty()
{
    # code...
    $data['areaList'] = $this->property_model->areaList();
    $data['propertyCityList'] = $this->property_model->propertyCityList();
    $this->global['pageTitle'] = 'RoxAI-ePro : Property List';
    $this->loadViews("property/listProperty", $this->global, $data, NULL);
}
public function getPropertyDatatable()
{
    # code...
    $listProperty = $this->property_model->getPropertyDatatable();

    $data = array();
    foreach ($listProperty as $property) {
        # code...
        $added_on=$property->property_added_on;
        $added_on_date = str_replace('/', '-', $added_on);
        $property_added_on_date=date('d/m/Y', strtotime($added_on_date));

        $row = array();
        $row[] = $property_added_on_date;
        $row[] = $property->property_asys_number;
        $row[] = $property->property_address;
        $row[] = $property->city_name;
        $row[] = 'Action';

        $data[] = $row;
    }
    $output = array(
        'draw' => $_POST['draw'],
        'recordsTotal' => $this->property_model->countPropertyAll(),
        'recordsFiltered' => $this->property_model->countPropertyFiltered(),
        'data' => $data,
    );
    echo json_encode($output);
}

Мой вопрос заключается в том, как передать значения этого раскрывающегося списка в URL, чтобы получить тот же результат напрямую, если я пытаюсь copy-paste URL, и открыть его в другом браузере с помощьютот же выбор значений в раскрывающемся списке?

...