Welcome Guest, Not a member yet? Register   Sign In
Is this right for a controller?
#1

[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;
  
   }

}
?>


Messages In This Thread
Is this right for a controller? - by El Forum - 05-25-2012, 07:02 AM
Is this right for a controller? - by El Forum - 05-25-2012, 07:17 AM
Is this right for a controller? - by El Forum - 05-25-2012, 07:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB