【问题标题】:Not able to call another controller method in codeigniter无法在 codeigniter 中调用另一个控制器方法
【发布时间】:2017-04-26 05:57:52
【问题描述】:

我正在为每个租户创建一个新数据库作为设置的一部分,db 已成功创建,但需要很长时间,大约 5 分钟,另一方面,我无法调用另一个控制器方法,即admin_list 控制器和其中的 manage_package 方法。这是我的控制器代码:

<?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);

       
    }

	   
}
  
?>

【问题讨论】:

标签: php codeigniter codeigniter-3


【解决方案1】:

您可以将控制器作为库加载到Codeigniter2。但我认为Codeigniter3是不可能的。

将控制器加载为库:

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

# Calling Methdod

$this->controller_name->method_name();

【讨论】:

  • 在添加 $this->load->library('../controllers/admin_list'); 时出现空白屏幕;
  • 您使用的是哪个版本的 Codeigniter,2 还是 3?
  • 设置错误报告并告诉我你遇到了什么错误。
  • 遇到 PHP 错误严重性:通知消息:未定义属性:admin_init_elements::$db 文件名:libraries/admin_init_elements.php 行号:136
  • 如果错误报告在语句之前设置为all,则会出现此错误,否则页面变为空白
猜你喜欢
  • 2011-09-23
  • 2020-07-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多