duankang5285 2018-10-08 19:00
浏览 47
已采纳

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

I am working on a basic blog application with Codeigniter 3.1.8 and Bootstrap 4.

I use migration files (001_create_authors.php up to 005_create_comments.php) to automatically create the necessary database tables.

The controller running the migrations is at

application/controllers/Migrate.php

It has the flowing 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 {
      echo 'Migration executed';
    }
  }
}

The default controller is the Posts controller, as the routes.php file shows: $route['default_controller'] = 'posts';

I would like the Posts controller to redirect to the Migrate one, if there are no tables in the database. Does Codeigniter have a method to determine if there are no tables? How shall I use it?

  • 写回答

2条回答 默认 最新

  • drk49438 2018-10-08 19:25
    关注

    https://www.codeigniter.com/user_guide/database/metadata.html

    if (count($this->db->list_tables()) == 0) {
        redirect(...);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序