CodeIgniter Forums
Search With Pagination ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Search With Pagination ? (/showthread.php?tid=74416)



Search With Pagination ? - rmcdahal - 09-20-2019

I am having an issue with search with pagination .. 
My Controller Code is 

Code:
public function search($keyword= null){
        $keyword = $this->request->getVar('search');
        if ($keyword==null) {
            return redirect('admin/media');
        }else{
            $data['medias'] = $MediaModel->search($keyword);
            $data = [
                'medias' => $MediaModel->paginate(3),
                'pager' => $MediaModel->pager
            ];
            // Page Heading
            $data['page_heading'] = 'Manage Media';
            $data['content_view'] = 'Demo\Media\Views\Manage';
            echo view('Demo\Themes\Views\Base', $data);
        }
        
    }

My Model Code is 
Code:
public function search($keyword){
        $builder = $this->db->table($this->table);
        $builder->like('media_name', $keyword);
        $query = $builder->get();
        return $query->getResultArray();
    }

Help Please Search is Not working,showing all data


RE: Search With Pagination ? - includebeer - 09-20-2019

PHP Code:
$data['medias'] = $MediaModel->search($keyword); 

the result is overwritten by


PHP Code:
$data = [
                'medias' => $MediaModel->paginate(3),
                'pager' => $MediaModel->pager
            
];