Welcome Guest, Not a member yet? Register   Sign In
I can use this Sigleton?
#1
Wink 

(models) User_model.php:

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
User_model extends CI_Model {

    private static 
$instance;

    public static function 
newInstance() {
        if(!
self::$instance instanceof self) {
            
self::$instance = new self;
        }
        return 
self::$instance;
    }
    
    public function 
__construct() {
        
parent::__construct();
    }

    public function 
getUserById($id) {
        
$this->db->select('*');
        
$this->db->from('ci_t_user');
        
$this->db->where('pk_i_id'$id);
        
$query $this->db->get();
        
$result $query->row();
        return 
$result;
    }

}
?>

(helpers) user_helper.php:

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if (!
function_exists('get_user_name')) {
    function 
get_user_name($id) {
        
//$ci =& get_instance();
        //$user = $ci->user_model->getUserById($id);
        
$user user_model::newInstance()->getUserById($id);
        return 
$user->s_name;
    }
}

?>

Or must I use get_instance (); ?
Reply


Messages In This Thread
I can use this Sigleton? - by adrianolmedo - 04-12-2016, 09:12 AM
RE: I can use this Sigleton? - by wishmaster - 04-19-2016, 07:40 AM



Theme © iAndrew 2016 - Forum software by © MyBB