如何修复 codeigniter -4 中的 dbforge 问题

How can fixup dbforge problem in codeigniter -4

当我尝试使用带有 dbforge 的 codeigniter 版本 4 插入新列时。

我在生产模式下遇到错误:

Whoops!We seem to have hit a snag. Please try again later...

public function addLanguage()
{ 
    $language = preg_replace('/[^a-zA-Z0-9_]/', '', $this->request->getPost('language',FILTER_SANITIZE_STRING));

    $language = strtolower($language);

    if (!empty($language)) {

        if (!$this->db->fieldExists($language, "language")) {

            $this->dbforge->addColumn("language", [
                $language => [
                    'type' => 'TEXT'
                ]
            ]); 

            $this->session->setFlashdata('message', 'Language added successfully');

            return redirect()->route('backend/setting/language');
        } 

    } else {
        $this->session->setFlashdata('exception', display('please_try_again'));
    }
    return redirect()->route('backend/setting/language');
}

我在这段代码中做错了什么?任何可能的帮助将不胜感激!

Development mode error image below:

您可以使用此代码

public function addLanguage()
    { 
        $dbforge = \Config\Database::forge();
      
        $language = preg_replace('/[^a-zA-Z0-9_]/', '', $this->request->getPost('language',FILTER_SANITIZE_STRING));

        $language = strtolower($language);
        if (!empty($language)) {
            if (!$this->db->fieldExists($language, "language")) {
  
                
                $dbforge->addColumn("language", [
                    $language => [
                        'type' => 'TEXT'
                    ]
                ]); 

                $this->session->setFlashdata('message', 'Language added successfully');
                return redirect()->route('backend/setting/language');
            } 
        } else {
            $this->session->setFlashdata('exception', display('please_try_again'));
        }
        return redirect()->route('backend/setting/language');
    }