0

I'm working with CodeIgniter for and Select2 to populate search results. It is working well but the populated data doesn't have a link. Can someone point me to the right direction? Here is my controller:

public function ajaxSearch()
{
    helper(['form', 'url']);

    $data = [];

    $db      = \Config\Database::connect();
    $builder = $db->table('courses');   

    $query = $builder->like('courseName', $this->request->getVar('q'))
                ->select('courseID, courseName as text')
                ->limit(10)->get();
    $data = $query->getResult();
     
    echo json_encode($data);
}

Here my view:

<script>
   
    $('.search').select2({
        placeholder: '--- What do you want to learn today? ---',
        ajax: {
            url: '<?php echo base_url('Home/ajaxSearch');?>',

            dataType: 'json',
            delay: 250,
            processResults: function(data){
                return {
                    results: data
                };
            },
            cache: true
        }
    });
</script>
<select class="search form-control" name="search"></select>         
I am usiing CDN to get the JS and css files. I need it to have a link on the results to go to the course id href="../course/<?php echo $course->courseID;?>
PaulMDG
  • 15
  • 1
  • 10

0 Answers0