dsnrixf6765 2017-04-26 05:57
浏览 75
已采纳

无法在codeigniter中调用另一个控制器方法

I am creating a new database as part of the setup for each of my tenants, db is created successfully but is taking a lot of time , approx 5 min, on the other hand i am not able to call another controller method i.e admin_list controller and manage_package method inside it. This is my controller code:

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

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

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

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

 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");
      echo $username;
     // $this->admin_list->manage_package();
      $this->load->dbforge();

    
  if ($this->dbforge->create_database($username))
{
    try{
      $current_database = $username;
      $this->db->database = $current_database;
    
     $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
                                          ),
                        'home_bg' => array(
                                                 '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
                                          ),
                        'username' => array(
                                             'type' => 'VARCHAR',
                                                 'constraint' => '255',
                                                 'default' => 'admin@fold.com',
                                          ),
                        'userpass' => array(
                                                 'type' => 'VARCHAR',
                                                 'constraint' => '255',
                                                 'default' => '65e1b655a6d6f4cbed20554d3b52521a743afdc0', 
                                          ),
                        'email' => array(
                                                 'type' =>'VARCHAR',
                                                 'constraint' => '255',
                                                 'default' => 'admin@fold.com', 
                                          ),
                        'departmentid' => array(
                                                  'type' => 'BIGINT',
                                                 'constraint' => 15,
                                               'default' => '1', 
                                                 
                                          ),
                        'userroleid' => array(
                                                  'type' => 'BIGINT',
                                                 'constraint' => 15,
                                               'default' => '4', 
                                                 
                                          ),
                        'managerid' => array(
                                                 'type' =>'VARCHAR',
                                                 'constraint' => '255',
                                                  'default' => '10', 
                                          ),
                        'userlevel' => array(
                                                  'type' => 'INT',
                                                 'constraint' => 11,
                                               
                                                 
                                          ),
                        'branchid' => array(
                                                  'type' => 'INT',
                                                 'constraint' => 11,
                                               'default' => '2',
                                          ),
                        'is_global' => array(
                                                  'type' => 'TINYINT',
                                                 'constraint' => 4,
                                               
                                                 'default' => '0',
                                          ),
                        'registrationtime' => array(
                                                  'type' => 'INT',
                                                 'constraint' => 10,
                                               
                                                 
                                          ),
                        'timemodified' => array(
                                                'type' => 'BIGINT',
                                                'constraint' => 10,
                                               
                                                 
                                          ),
                        'modifierid' => array(
                                                  'type' => 'BIGINT',
                                                  'constraint' => 15,
                                               
                                                 
                                          ),
                                                  'status' => array(
                                                  'type' => 'TINYINT',
                                                  'constraint' => 1,
                                               
                                                 
                                          ),

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

                         'temppassvalidtill' => array(
                                                  'type' => 'BIGINT',
                                                 'constraint' => 15,
                                               
                                                 
                                          ),
                            'lastlogin' => array(
                                                  'type' => 'BIGINT',
                                                 'constraint' => 10,
                                               
                                                 
                                          ),
                           'lastrefresh' => array(
                                                  'type' => 'BIGINT',
                                                 'constraint' => 15,
                                               
                                                 
                                          ),
                                   'lastloginip' => array(
                                                  'type' => 'VARCHAR',
                                                 'constraint' => 20,
                                               
                                                 
                                          ),
                                   'if_online' => array(
                                                  'type' => 'INT',
                                                 'constraint' => 11,
                                               
                                                 
                                          ),
                                   '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);  
     
}



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

  }


      // then do whatever you want with it :)

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

       
    }

       
}
  
?>

</div>
  • 写回答

1条回答 默认 最新

  • doutu3352 2017-04-26 06:23
    关注

    You can load controller as library in Codeigniter2. But I don't think it is possible in Codeigniter3.

    Load Controller as Library :

    $this->load->library('../controllers/controller_name');
    
    # Calling Methdod
    
    $this->controller_name->method_name();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services