如何在CodeIgniter 3.1.1中使用数据库伪造类



现在我正在使用CodeIgniter 3.1.1开发一个新的应用程序,我需要通过添加新列或删除现有列来自定义数据库列。我已经阅读了CodeIgniter文档,我发现了Database Forge,但当我试图使用和遵循文档时,我遇到了一些错误!有人能帮我吗?

<?php 
class Setting extends CI_Controller{
function __construct(){
parent::__construct();      
$this->load->model('m_stock');
if($this->session->userdata('status') != "login"){
redirect(base_url("login"));
}
$forge = ConfigDatabase::forge();
}
function index(){
}
function tambah_cabang(){
$fields = [
'cabang_3' => ['type' => 'TEXT']
];
$forge->addColumn('barang', $fields);
}
}

错误消息:

An uncaught Exception was encountered
Type: Error
Message: Class 'ConfigDatabase' not found
Filename: E:xampphtdocsbelajarphpposapplicationcontrollersSetting.php
Line Number: 10
Backtrace:
File: E:xampphtdocsbelajarphpposindex.php
Line: 315
Function: require_once

我的user_master表中有它,根据需要进行调整

<?php
namespace AppDatabaseMigrations;
use CodeIgniterDatabaseMigration;
class UserMaster extends Migration
{
public function up()
{
$this->forge->addField([
'id' => [
'type' => 'INT',
'auto_increment' => TRUE
],
'name' => [
'type' => 'VARCHAR',
'constraint' => '50',
],
'username' => [
'type' => 'VARCHAR',
'constraint' => '50',
],
'password' => [
'type' => 'VARCHAR',
'constraint' => '50',
],
'access_level' => [
'type' => 'VARCHAR',
'constraint' => '50',
],
]);
$this->forge->addField("date_time timestamp DEFAULT CURRENT_TIMESTAMP");
$this->forge->addPrimaryKey('id', TRUE);
$this->forge->createTable('user_master');
}
//--------------------------------------------------------------------
public function down()
{
$this->forge->dropTable('user_master');
}
}

相关内容

  • 没有找到相关文章

最新更新