Welcome Guest, Not a member yet? Register   Sign In
Problem with loading model !
#1

[eluser][email protected][/eluser]
Hy all. I`m new to this forum even thought i use code igniter for some time now.
I have a very big problem :down:
This happens when trying to load a model from a controller

in my constructor i have :
parent::Controller();
$this -> load -> model('hosting_model','hosting',TRUE);
$this -> hosting_1 = $this->load->database('hosting',TRUE);


in function index i have:

$ext_name='.ro';
$x = $this->hosting->is_ext_unique($ext_name);


The error is :

Call to undefined method CI_DB_mysql_driver::is_ext_unique()

It doesn`t get tot the function in model because i put die in there and nothing happens...
I don`t know what to do...

In my model in constructor i have :

parent::Model();
$this->hosting = $this->load->database('hosting',TRUE);


i connect to my database in database.php from config .. here are the detailes

$db['hosting']['hostname'] = "localhost";
$db['hosting']['username'] = "Dragos";
$db['hosting']['password'] = "jught";
$db['hosting']['database'] = "hosting";
$db['hosting']['dbdriver'] = "mysql";
$db['hosting']['dbprefix'] = "";
$db['hosting']['active_r'] = TRUE;
$db['hosting']['pconnect'] = FALSE;
$db['hosting']['db_debug'] = TRUE;


... :roll:
#2

[eluser]alpar[/eluser]
Do you use the database in your model? Try loading it before the model.
#3

[eluser][email protected][/eluser]
I tried it. Same error .. Don`t know what to say.. I think that the problem is when loading the model because i tried it and if i load the model before the function is_ext_unique() it works.. the problem is that i use the model in maany functions and can`t modify all

$this -> load -> model(’hosting_model’,’hosting’,TRUE);
$ext_name=’.ro’;
$x = $this->hosting->is_ext_unique($ext_name);

it`s strange .. it seems that the model doesn`t load properly when i put it in the constructor of the controller...
#4

[eluser]alpar[/eluser]
maybe you should show us the model .... (use [ code ] tags so we can read it better )
#5

[eluser][email protected][/eluser]
Here is my controller. Please note that i use XAJAX but the error aperars even when i try to execute the function $this->hosting->is_ext_unique($ext_name); in my index like this:

Code:
function index()
{

            $ext_name='.ro';
                    $this->hosting->is_ext_unique($ext_name);
die();
}

here is the code from my controller..

Code:
class Command extends Controller {
    
    var $my_root;
    
    function command()
    {
        parent::Controller();
        
      
        $this -> load -> library('paginare');
        $this->load->library('xajax');
        $this -> load -> model('whois_model','ws', TRUE);
        $this -> load -> model('hosting_model','hosting',TRUE);
        $this -> load -> model('w2w_model','w2w_model', TRUE);
        $this -> load -> model('users_model','users');  
        $this -> way2web = $this->load->database('way2web',TRUE);
        $this -> hosting_1 = $this->load->database('hosting',TRUE);

    }

function index()
        {

        //$this -> way2web = $this->load->database('way2web',TRUE);



            $this->load->model('auth');
            if (!$this->auth->autorization())
            {
                    header('location: '.$this->config->item('base_url').'interzis');
            }
        $ss = $this->hosting->is_ext_unique($ext_name);
            $ext=$this->get_extensii();
                                
        $x['data']= $ext;

        $promotional_ext_prices = $this->get_extensions_and_prices(true);
        $normal_ext_prices = $this->get_extensions_and_prices();
        
//        print_r($normal_ext_prices);die;
        $x['promotional_ext_prices'] = $promotional_ext_prices;
        $x['normal_ext_prices'] = $normal_ext_prices;
//        print_r($promotional_ext_prices);die;
        $x['user_id'] = $_SESSION['user_id'];
        $x['titlu'] = 'Administrare useri ...';
        $x['left'] = '';
        $x['body'] = 'body/command';
        $x['menu_title'] = 'Hosting & domenii';
        $categories = $this->get_category();
//        print_r($categories);die;
        $x['categories'] = $categories;
        foreach($categories as $cur_cat)
        {
            if(($cur_cat['category_code']!='h')&&($cur_cat['category_code']!='d'))
            {
                $data_1 = $this->get_products_per_category($cur_cat['category_id']);
                $i=0;
                //print_r($data_1);die;
                foreach($data_1 as $prod_data)
                {
                    $product_categories[$cur_cat['category_id']][$i]['nume'] = $prod_data['name'];
                    $product_categories[$cur_cat['category_id']][$i]['description'] = $prod_data['description'];                    $product_categories[$cur_cat['category_id']][$i]['product_id'] = $prod_data['product_id'];
                    $i++;
                }
            }
        }
        $x['product_per_category'] = $product_categories;
//print_r($product_categories);die;
        $x['localizare'] = array(
            array('localizare_url' => '/', 'localizare_text'=>'Home'),
            array('localizare_url' => '', 'localizare_text'=>'Hosting & domenii')
        );
        $x['my_root'] = $this -> my_root;
        
    $classes = $this->get_class_by_resseler($this->config->item('reseller_id'));
            for($i=0;$i<sizeof($classes);$i++)
        {

            $t = $this->get_package_by_class($classes[$i]['class_id']);    

            for($j=0;$j<sizeof($t);$j++)
            {
                $package[$classes[$i]['class_id']][$j]['pack_name'] = $t[$j]['package_name'];
                $package[$classes[$i]['class_id']][$j]['pack_id'] = $t[$j]['package_id'];
                $package[$classes[$i]['class_id']][$j]['quota'] = $t[$j]['quota'];
                $package[$classes[$i]['class_id']][$j]['package_price'] = $t[$j]['package_price'];
                $package[$classes[$i]['class_id']][$j]['pack_frequency'] =     $this->get_frequency_by_package($t[$j]['package_id']);
            }
        }
            //print_r($package);die;
            
            $x['classes']=$classes;
            $x['package']=$package;

            $countries = $this->w2w_model->get_countries();

        $users = $this->users->get_users();
        $user_m=array();
    foreach($users as $ky=>$current_user)
    {
        if($current_user['user_id']==$_SESSION['user_id'])
        {
            $user_m[0]=$users[$ky];
        }
    }

    $x['countries'] = $countries;
    $x['users']=$user_m;

    $this->xajax->registerFunction(array('dm_java_available',&$this,'dm_java_available'));
    $this->xajax->registerFunction(array('is_extension_unique',&$this,'is_extension_unique'));
    
        
     $this->xajax->processRequests();
    $x['xajax_js'] = $this->xajax->getjavascript(null, 'http://www.way2web.ro/js/xajax.js');
    
    
    $admin_id=$this->users->get_admin_id();

    $preferences = $this->w2w_model->get_user_preferences($admin_id[0]['user_id']);

    $x['tva_add'] = $preferences[0]['tva_add'];

     $this->load->view('structure',$x);
    }

function is_extension_unique($ext_name)
    {
    $objResponse = new xajaxResponse();

    $x = $this->hosting->is_ext_unique($ext_name);
    if($x)
    {
        $objResponse->addScript('document.getElementById("freq").options.length=0;');
        $objResponse->addScript('document.getElementById("freq").options[0]=new Option("Pe Viata", "1", true, true);');
}    
return $objResponse->getXML();
#6

[eluser]alpar[/eluser]
i meant the model called "hosting" as i think the problem is in there
#7

[eluser][email protected][/eluser]
If i load the model at the end of my constructor it works.. don`t know why .. strange stuff..

Code:
function command()
    {
        parent::Controller();
        
        $this -> way2web = $this->load->database('way2web',TRUE);
        $this -> hosting_1 = $this->load->database('hosting',TRUE);      
        $this -> load -> library('paginare');
        $this->load->library('xajax');
        $this -> load -> model('whois_model','ws', TRUE);
        $this -> load -> model('w2w_model','w2w_model', TRUE);
        $this -> load -> model('users_model','users');  
        $this -> load -> model('hosting_model','hosting',TRUE);


    }
Here is my code for the model :


Code:
class Hosting_model extends Model {
        
        var $DB1;
        
    function Hosting_model()
    {
        parent::Model();
                //$this -> load -> model($this -> my_root . 'models/hosting_model','hosting', TRUE);
                $this->hosting = $this->load->database('hosting',TRUE);
                $this->way2web = $this->load->database('way2web',TRUE);
    }
    function is_ext_unique($ext_name)
    {
        $sql='SELECT * FROM  extensions WHERE extension = \''.$ext_name.'\' AND unique_price_ext ="1"';
        $query = $this -> hosting -> query( $sql );
        $result = $query -> result_array();

        if($query->num_rows()>0)
        {
            return true;
            
        }
        else
        {
            return false;
        }
    }


}




Theme © iAndrew 2016 - Forum software by © MyBB