Welcome Guest, Not a member yet? Register   Sign In
Unable to get at functions within library in HMVC MX_Controller (SOLVED)
#1

[eluser]bugboy[/eluser]
Hi have an issue using MX_controller and getting a function with a library.

This is my library (Subdomain.php)

Code:
class Subdomain
{

    /**
     * Constructor
     *
     * @access public
     */
    
     var $_subdomain;
     var $_profiles = array();

    
    function Subdomain()
    {
        $this->ci =& get_instance();        
        $this->ci->load->database();
        $this->ci->load->model('users/users');
        $this->_set_subdomain();
        log_message('debug', "Subdomain Class Initialized");
        
        // echo 'hello subdomains loaded'; this is to prove its autoloaded
        
    }
    
    
    /**
    private
    function to get subdomain value
    **/
    
    function _set_subdomain ()
    {
        // set the array that holds the profiles
        $this->_profiles = $this->ci->users->get_usernames();
        // get the library input
        $this->ci->load->library('Input', TRUE);
        // like, such as, 'sub.example.com'
        $host = strtolower($this->ci->input->server('HTTP_HOST'));
        // and now we'll get: array('sub', 'example', 'com');
        $account = explode('.', $host);
        // if there's a subdomain, and it's not 'www'... then that's the account name.
        // count > 3 for a .co.uk // 2 for a .com
        $account = (count($account) > 3 && $account[0] != 'www') ? array_shift($account) : false;
        $this->_subdomain = $account;
    }
    
    
    /**
    public
    function returns the subdomain
    **/
    
    function get_subdomain()
    {
        return $this->_subdomain;
    }    
    
    
    /**
    public
    function checks if domain is already in use
    **/
    
    function check_subdomain()
    {
        if(in_array($this->_subdomain, $this->_profiles))
        {
            return TRUE;
        }
        return FALSE;
    }
    
    
    /**
    public
    function gets profile for user
    **/
    
    function get_profile()
    {
        return $this->ci->users->get_user_by_username($this->_subdomain);
    }
    
    
}

This is my MX_Controller

Code:
class MX_Controller extends Controller
{
    function __construct()
    {
        parent::Controller();
    }
}


class Public_Controller extends MX_Controller
{
    var $subdomain;
    var $profile;
    
function __construct()
    {
        parent::Controller();
                
        $this->subdomain = $this->subdomain->get_subdomain();
        $this->profile = $this->subdomain->get_profile();
        
        $this->check();
        
    }
    
    function check()
    {
        if($this->_subdomain === FALSE)
        {
            // no profile given load the welcome page
            redirect('/', 'location');
        }
        else
        {
            if($this->subdomain->check_subdomain() === FALSE)
            {
                // profile is available load the available page
                redirect('/', 'location');
            }
        }
    }
}

and this is the error I'm getting

Fatal error: Call to a member function get_subdomain() on a non-object in /application/libraries/MX_Controller.php on line 20

I'm completely stuck on this.
#2

[eluser]bugboy[/eluser]
Ok its seems so stupid now but it was a naming issue. I had a variable named the same as the library.

Which caused the conflicts




Theme © iAndrew 2016 - Forum software by © MyBB