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

}
?>
#2

[eluser]mfroseth[/eluser]
I meant model!
#3

[eluser]Rolly1971[/eluser]
if your looking to create a model class you need to extend CI_Model, not CI_Controller

Code:
class Agents extends CI_Model
{

function __construct()
{
   parent::__construct()
}

function myFunction()
{
   // ... do something
}

}




Theme © iAndrew 2016 - Forum software by © MyBB