Welcome Guest, Not a member yet? Register   Sign In
How to perform this in CodeIgniter MVC
#5

That's where the model concept comes in.
Create a model like this:
Filename: application/models/User_model.php
PHP Code:
class User_model extends CI_Model {
 
 public function get_names_without_aaa()
 
 {
 
    $users = array();
 
    $query $this->db->get('users');    //get is a function in the query builder!
 
    foreach ($query->result_array() AS $row) {
 
       $FirstName str_replace('aaa','***',$row['FirstName']);
 
       $users[] = array("FirstName"=>$FirstName);
 
    }
 
    return $users  
  
}


In the controller:
PHP Code:
$this->load->model('user_model');
$data['users'] = $this->user_model->get_names_without_aaa();
$this->load->view('myview',$data); 

Now, you can load the model in any controller you want, or even autoload it in application/config/autoload.php.
Reply


Messages In This Thread
RE: How to perform this in CodeIgniter MVC - by Wouter60 - 05-08-2016, 04:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB