2017-04-26 138 views
0

我正在爲每個租戶創建一個新的數據庫作爲安裝的一部分,db已成功創建,但需要大量時間,大約5分鐘,另一方面,我我無法調用其他控制器方法,即其中的admin_list控制器和manage_package方法。這是我的控制器代碼:無法在codeigniter中調用另一個控制器方法

<?php 
 
class login extends CI_Controller 
 
{ 
 
    var $data; 
 

 
    function __construct() { 
 
     parent::__construct(); 
 
\t \t $this->load->helper('cookie'); 
 
\t \t require_once(APPPATH.'controllers/admin_list.php'); 
 

 
\t \t $is_admin_logged_in = $this->admin_init_elements->admin_logged_in_status(); 
 
\t \t global $USER; 
 
\t \t if($is_admin_logged_in == TRUE){ 
 
\t \t \t redirect('home'); 
 
\t \t \t //; 
 
     } 
 

 
     //populate viewfor header/footer elements 
 
     
 
     $this->admin_init_elements->init_elements('N'); 
 
\t \t $this->load->model('mod_login'); 
 
\t \t 
 
    } 
 

 
public function save_userinput() 
 
    { 
 
     //code goes here 
 
     // for example: getting the post values of the form: 
 
     $form_data = $this->input->post(); 
 
     // or just the username: 
 
     $username = $this->input->post("username"); 
 
\t echo $username; 
 
\t // $this->admin_list->manage_package(); 
 
     $this->load->dbforge(); 
 

 
\t 
 
    if ($this->dbforge->create_database($username)) 
 
{ 
 
    try{ 
 
     $current_database = $username; 
 
     $this->db->database = $current_database; 
 
\t 
 
    $this->db->close(); 
 
    $config['hostname'] = "localhost"; 
 
    $config['username'] = "root"; 
 
    $config['password'] = ""; 
 
    $config['database'] = $current_database; 
 
    $config['dbdriver'] = "mysql"; 
 
    $config['dbprefix'] = $username; 
 
    $config['pconnect'] = FALSE; 
 
    $config['db_debug'] = TRUE; 
 
    $config['cache_on'] = FALSE; 
 
    $config['cachedir'] = ""; 
 
    $config['char_set'] = "utf8"; 
 
    $config['dbcollat'] = "utf8_general_ci"; 
 
    $this->load->database($config); 
 
    $fields = array(
 
         'id' => array(
 
               'type' => 'INT', 
 
               'constraint' => 11, 
 
               'unsigned' => TRUE, 
 
               'auto_increment' => TRUE 
 
             ), 
 
\t \t \t \t \t \t 'home_bg' => array(
 
               \t 'type' => 'VARCHAR', 
 
               'constraint' => '200', 
 
             ), 
 
         'login_bg' => array(
 
               'type' => 'VARCHAR', 
 
               'constraint' => '200', 
 
             ), 
 
         'other_bg' => array(
 
               'type' =>'VARCHAR', 
 
               'constraint' => '200', 
 
                
 
             ), 
 
         'uploaded_on' => array(
 
               'type' => 'DATE', 
 
                
 
             ), 
 
       ); 
 

 
    $this->dbforge->add_field($fields); 
 
    $this->dbforge->add_key('id', TRUE); 
 
    $this->dbforge->create_table('pr_backgrounds', TRUE); 
 

 

 

 
$fields = array(
 
         'id' => array(
 
               'type' => 'BIGINT', 
 
               'constraint' => 15, 
 
               'unsigned' => TRUE, 
 
               'auto_increment' => TRUE 
 
             ), 
 
\t \t \t \t \t \t 'username' => array(
 
              'type' => 'VARCHAR', 
 
               'constraint' => '255', 
 
\t \t \t \t \t \t \t \t \t \t \t \t 'default' => '[email protected]', 
 
             ), 
 
         'userpass' => array(
 
               'type' => 'VARCHAR', 
 
               'constraint' => '255', 
 
\t \t \t \t \t \t \t \t \t \t \t \t 'default' => '65e1b655a6d6f4cbed20554d3b52521a743afdc0', 
 
             ), 
 
         'email' => array(
 
               'type' =>'VARCHAR', 
 
               'constraint' => '255', 
 
               'default' => '[email protected]', 
 
             ), 
 
         'departmentid' => array(
 
                'type' => 'BIGINT', 
 
               'constraint' => 15, 
 
               'default' => '1', 
 
                
 
             ), 
 
\t \t \t \t \t \t 'userroleid' => array(
 
                'type' => 'BIGINT', 
 
               'constraint' => 15, 
 
               'default' => '4', 
 
                
 
             ), 
 
\t \t \t \t \t  'managerid' => array(
 
               'type' =>'VARCHAR', 
 
               'constraint' => '255', 
 
                'default' => '10', 
 
             ), 
 
\t \t \t \t \t \t 'userlevel' => array(
 
                'type' => 'INT', 
 
               'constraint' => 11, 
 
               
 
                
 
             ), 
 
\t \t \t \t \t \t 'branchid' => array(
 
                'type' => 'INT', 
 
               'constraint' => 11, 
 
               'default' => '2', 
 
             ), 
 
\t \t \t \t \t \t 'is_global' => array(
 
                'type' => 'TINYINT', 
 
               'constraint' => 4, 
 
               
 
               'default' => '0', 
 
             ), 
 
\t \t \t \t \t \t 'registrationtime' => array(
 
                'type' => 'INT', 
 
               'constraint' => 10, 
 
               
 
                
 
             ), 
 
\t \t \t \t \t \t 'timemodified' => array(
 
               'type' => 'BIGINT', 
 
               'constraint' => 10, 
 
               
 
                
 
             ), 
 
\t \t \t \t \t  'modifierid' => array(
 
                'type' => 'BIGINT', 
 
                'constraint' => 15, 
 
               
 
                
 
             ), 
 
\t \t \t \t \t \t \t \t \t \t \t  'status' => array(
 
                'type' => 'TINYINT', 
 
                'constraint' => 1, 
 
               
 
                
 
             ), 
 

 
\t \t   'deleted' => array(
 
                'type' => 'TINYINT', 
 
                'constraint' => 1, 
 
               
 
                
 
             ), 
 
\t \t \t \t  'temppass' => array(
 
                'type' => 'VARCHAR', 
 
                'constraint' => 20, 
 
               
 
                
 
             ), 
 

 
\t \t \t \t \t  'temppassvalidtill' => array(
 
                'type' => 'BIGINT', 
 
               'constraint' => 15, 
 
               
 
                
 
             ), 
 
\t \t \t \t \t \t  'lastlogin' => array(
 
                'type' => 'BIGINT', 
 
               'constraint' => 10, 
 
               
 
                
 
             ), 
 
\t \t \t \t \t \t 'lastrefresh' => array(
 
                'type' => 'BIGINT', 
 
               'constraint' => 15, 
 
               
 
                
 
             ), 
 
\t \t \t \t \t \t \t \t 'lastloginip' => array(
 
                'type' => 'VARCHAR', 
 
               'constraint' => 20, 
 
               
 
                
 
             ), 
 
\t \t \t \t \t \t \t \t 'if_online' => array(
 
                'type' => 'INT', 
 
               'constraint' => 11, 
 
               
 
                
 
             ), 
 
\t \t \t \t \t \t \t \t 'pfield' => array(
 
                'type' => 'VARCHAR', 
 
               'constraint' => 255, 
 
               
 
                
 
             ), 
 
       ); 
 

 
    $this->dbforge->add_field($fields); 
 
    $this->dbforge->add_key('id', TRUE); 
 
    $this->dbforge->create_table('pr_users', TRUE); 
 

 

 
$sql = file_get_contents("assets/bizzlatestdb.sql"); 
 

 
/* 
 
Assuming you have an SQL file (or string) you want to run as part of the migration, which has a number of statements... 
 
CI migration only allows you to run one statement at a time. If the SQL is generated, it's annoying to split it up and create separate statements. 
 
This small script splits the statements allowing you to run them all in one go. 
 
*/ 
 

 
$sqls = explode(';', $sql); 
 
array_pop($sqls); 
 

 
foreach($sqls as $statement){ 
 
    $statment = $statement . ";"; 
 
    $this->db->query($statement); 
 
\t 
 
} 
 

 

 

 
    } 
 
\t 
 
\t catch(Exception $e){ 
 
     echo "This name already exists in our database , Please choose another company name"; 
 
\t die; 
 
    } 
 
    $this->admin_list->manage_package(); 
 

 
    } 
 

 

 
     // then do whatever you want with it :) 
 

 
    } 
 
    function index(){ 
 
    
 
\t \t 
 
\t \t $this->load->view('login', $this->data); 
 

 
     
 
    } 
 

 
\t  
 
} 
 
    
 
?>

+0

參考,[此](http://stackoverflow.com/questions/14165895/how-to-load-a-controller-from-another-controller- in-codeigniter)回答 –

+0

你真正的問題是什麼?也請務必閱讀http://stackoverflow.com/help/how-to-ask –

+0

你應該嘗試這個鏈接http://stackoverflow.com/questions/9494492/codeigniter-extending-multiple-controllers –

回答

3

可以在Codeigniter2負載控制器庫。但我認爲這不可能在Codeigniter3

負載控制器作爲庫:

$this->load->library('../controllers/controller_name'); 

# Calling Methdod 

$this->controller_name->method_name(); 
+0

給出一個空白添加$ this-> load-> library('../ controllers/admin_list'); – sunshine

+0

你正在使用什麼版本的Codeigniter,2或3? –

+0

codeigniter版本2 – sunshine

相關問題