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();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能