[eluser]ronald_allan_rivera[/eluser]
controllers/domain.php
Code:
<?
class Domain extends Controller{
function index() { // Forcing the use of page function…
redirect('domain/page/1');
}
function search() {
$terms = array();
if ($this->uri->segment(3)!='') {
$search = $this->uri->segment(3);
$search = str_replace(' ','-',$search);
//valid_char_only($search); // Function to remove accents and invalid characters, use any function
// Preparando array
$aux = explode('-',$search);
foreach($aux as $key => $valor) {
$terms[] = $valor;
}
} else {
$search = $this->input->post('keyword');
$search = str_replace(' ','-',$search);
// Preparando array
$aux = explode('-',$search);
foreach($aux as $key => $valor) {
$terms[] = $valor;
}
}
/
redirect('domain/page/1/'.$search);
}
function page($page='',$terms='') {
if ($page=='') {
redirect('domain/page/1');
}
if ($this->uri->segment(4)!='') {
$terms = $this->uri->segment(4);
}
$this->load->library('pagination_search');
$limit = 20;
$offset = ($page-1)*$limit;
if ($terms=='') {
$this->db->limit($limit, $offset);
$query = $this->db->get('domain');
$data['total'] = $query->num_rows();
} else {
$search = str_replace(' ','-',$terms);
// Preparing array
$mysearch = array();
$aux = explode('-',$search);
foreach($aux as $key => $valor) {
$mysearch[] = $valor;
}
$this->db->like('domain_name', $mysearch[0]);
//$this->db->or_like('id', $mysearch[0]);
//$this->db->or_like('description', $mysearch[0]);
$tt = count($mysearch);
if ($tt>0) {
for ($j=1;$j<$tt;$j++) {
$this->db->or_like('domain_name', $mysearch[$j]);
//$this->db->or_like('id', $mysearch[$j]);
//$this->db->or_like('description', $mysearch[$j]);
}
}
$query_tt = $this->db->get('domain');
$this->db->like('domain_name', $mysearch[0]);
$tt = count($mysearch);
if ($tt>0) {
for ($j=1;$j<$tt;$j++) {
$this->db->or_like('domain_name', $mysearch[$j]);
}
}
$this->db->limit($limit, $offset);
$query = $this->db->get('domain');
$data['total'] = $query_tt->num_rows();
}
$config['base_url']= site_url() . '/domain/page/';
$config['total_rows'] = $data['total'];
$config['per_page'] = $limit;
$config['uri_segment'] = 3;
$config['num_links'] = 5;
$this->pagination_search->initialize($config);
$data['num_of_pages'] = round($data['total'] / $limit);
$data['domain'] = $query;
$data['links']=$this->pagination_search->create_links($search);
$data['search'] = $search;
$this->load->view('domain',$data);
}
}
?>