Welcome Guest, Not a member yet? Register   Sign In
How do I load dbforge out of CI
#1

In the name of Allah, Hi, I‌ was trying to load dbforge in my created class, but when i use functions of dbforge i received errors.
PHP Code:
class plugin_utility
{
    private 
$CI;
    private 
$name;
    public function 
__construct($name) {
         
$this->CI =& get_instance();
         
$this->name=$name;
         if(
$this->checklang())
         {
             
$this->CI->lang->plg_load($name,$name);             
         }
     
    }    
    public function 
install_db($options)
    {
        
$this->CI->load->dbforge();
        
        if(
is_array($options['tables']) && count($options['tables']>0))
        {
            
            foreach(
$options['tables'] as $key=>$table)
            {
                
$this->CI->dbforge->add_field($table['fields']);
                if(
is_array($table['keys']))
                {
                    foreach(
$table['keys'] as $k)
                    {
                        
$this->CI->dbforge->add_key($kTRUE);
                    }
                }else{
                    
$this->CI->dbforge->add_key($table['keys'], TRUE);
                }
                
                if(
$this->CI->dbforge->create_table($keyTRUE))
                {
                    
insert_plugin_headers($this->name);
                    
//enable_plugin($this->name);
                    
$result = array("result" => "ok""result_message" => "<ul><li>".$this->CI->lang->line('success_plugin_installation')."</li></ul>");
                }else{
                    
$result = array("result" => "null""result_message" => "<ul><li>".$this->CI->lang->line('failure_plugin_installation')."</li></ul>");
                }
                
                return 
$result;
            }
            
        }
    }    
    public function 
uninstall_db($options)
    {
        
$this->CI->load->dbforge();
        
        if(
is_array($options['tables']) && count($options['tables']>0))
        {
            
            foreach(
$options['tables'] as $table)
            {        
                if(
$this->dbforge->drop_table($table,TRUE))
                {
                    
$result = array("result" => "ok""result_message" => "<ul><li>".$this->CI->lang->line('success_plugin_uninstallation')."</li></ul>");
                }else{
                    
$result = array("result" => "null""result_message" => "<ul><li>".$this->CI->lang->line('failure_plugin_uninstallation')."</li></ul>");
                }
                
                return 
$result;
            }
            
        }
    }        
    public function 
copy_controllers()
    {
        
$path=PLUGINPATH.$this->name.'/core/controllers';
        
$dest_path=FCPATH.'store/controllers';
        if(
is_dir($path) && is_dir($dest_path))
        {        
            
copy_r($path,$dest_path);
        }            
    }
    public function 
delete_controllers()
    {
        
$this->CI->load->helper('directory');
        
$this->CI->load->helper('directory');
        
$path=PLUGINPATH.$this->name.'/core/controllers';
        
$dest_path=FCPATH.'store/controllers';
        if(
is_dir($path) && is_dir($dest_path))
        {        
            
$map directory_map($path);
            foreach(
$map as $folder=>$file)
            {
                if(
is_array($file))
                {
                    foreach(
$file as $k=>$v)
                    {
                        if(
file_exists($dest_path.DIRECTORY_SEPARATOR.$folder.$v))
                            @
unlink($dest_path.DIRECTORY_SEPARATOR.$folder.$v);
                    }
                    
                }else{
                        if(
file_exists($dest_path.DIRECTORY_SEPARATOR.$file))
                            @
unlink($dest_path.DIRECTORY_SEPARATOR.$file);
                }
            }
        }            
    }    

    private function 
checklang()
    {
        
$path=PLUGINPATH.$this->name.'/core/language';
        if(
is_dir($path))
        {
            return 
true;
        }
        return 
false;
    }    




PHP Code:
A PHP Error was encountered

Severity
Notice

Message
Undefined propertyplugin_utility::$dbforge

Filename
libraries/abstract.plugins.php

Line Number
196 
Reply
#2

In the name of Allah, Hi, I made mistake, I‌ should have changed the $this->dbforge->drop_table($table,TRUE) to $this->CI->dbforge->drop_table($table,TRUE)
Reply




Theme © iAndrew 2016 - Forum software by © MyBB