Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter 3应用程序:如果数据库中没有表,则重定向到某个控制器_Php_Codeigniter_Codeigniter 3 - Fatal编程技术网

Php Codeigniter 3应用程序:如果数据库中没有表,则重定向到某个控制器

Php Codeigniter 3应用程序:如果数据库中没有表,则重定向到某个控制器,php,codeigniter,codeigniter-3,Php,Codeigniter,Codeigniter 3,我正在使用Codeigniter 3.1.8和Bootstrap 4开发一个基本的博客应用程序 我使用迁移文件(001\u create\u authors.php005\u create\u comments.php)自动创建必要的数据库表 运行迁移的控制器位于 application/controllers/Migrate.php 它具有流动代码: class Migrate extends CI_Controller { public function __construct()

我正在使用Codeigniter 3.1.8和Bootstrap 4开发一个基本的博客应用程序

我使用迁移文件(
001\u create\u authors.php
005\u create\u comments.php)自动创建必要的数据库表

运行迁移的控制器位于

application/controllers/Migrate.php

它具有流动代码:

class Migrate extends CI_Controller
{
  public function __construct()
  {
    parent::__construct();
  }

  public function index()
  {
    $this->load->library('migration');

    if($this->migration->current() === FALSE)
    {
      show_error($this->migration->error_string());
    }
    else {
      echo 'Migration executed';
    }
  }
}
默认控制器是
Posts
控制器,如
routes.php
文件所示:
$route['default_controller']='Posts'

如果数据库中没有表,我希望
Posts
控制器重定向到
Migrate
one。Codeigniter是否有确定是否没有表格的方法?我该如何使用它?


我通过这种精确的方式得到了想要的结果:

在Posts控制器中(默认):

在迁移控制器中:

class Migrate extends CI_Controller
{
  public function __construct()
  {
    parent::__construct();
  }

  public function index()
  {
    $this->load->library('migration');

    if($this->migration->current() === FALSE)
    {
      show_error($this->migration->error_string());
    }
    else {
      $this->session->set_flashdata('tables_created', "All the required database tables have been created. You can now register.");
      redirect('/');
    }
  }
}
public function index() {
  // Create all the database tables if there are none
  // by redirecting to the Migrations controller
    if (count($this->db->list_tables()) == 0) {
       redirect('migrate');
     }
     // More code
}
class Migrate extends CI_Controller
{
  public function __construct()
  {
    parent::__construct();
  }

  public function index()
  {
    $this->load->library('migration');

    if($this->migration->current() === FALSE)
    {
      show_error($this->migration->error_string());
    }
    else {
      $this->session->set_flashdata('tables_created', "All the required database tables have been created. You can now register.");
      redirect('/');
    }
  }
}