[eluser]mfroseth[/eluser]
Trying to grasp this Controller/Model thing. Am I doing this right?
Code:
<?php
class Agents extends CI_Controller {
function Agents_model()
{
parent::CI_Model();
}
function __construct()
{
$this->load->database();
parent::__construct();
}
function search()
{
$this->load->helper('inflector');
//say you get the search term from a form
$term = $this->input->post('search_term');
//you may want to inspect the term for special characters and take them out here
//get the singular form
$singular = singular($term);
//get the plural form
$plural = plural($singular);
$saxon_genitive = $singular . "\\'s " . $plural . "\\'";
$keywords = $singular . ' ' . $plural . ' ' . $saxon_genitive;
//then you can run the query from above in boolean mode
$results = $this->db
->select('lead_details')
->select("(MATCH(`first_name`, `last_name`, `email`, `phone`) AGAINST ('" . $keywords . "'))` AS score")
->where("(MATCH(`first_name`, `last_name`, `email`, `phone`) AGAINST ('" . $keywords . "'))")
->order_by('score', 'desc')
->get('lead_details')
->result_array();
return $results;
}
}
?>