gpt4 book ai didi

php - fatal error : Call to member function on a non-object Code Igniter

转载 作者:行者123 更新时间:2023-11-29 06:15:07 24 4
gpt4 key购买 nike

我按照模型文档进行操作,但不断收到此错误,我们将不胜感激。

遇到 PHP 错误

严重性:通知

消息:未定义的属性:管理::$文件

文件名:files/manage.php

行号:14

fatal error :在第 14 行/var/www/uisimulator/application/controllers/files/manage.php 中的非对象上调用成员函数 get_files()*

这是我的模型:-位于:application/models/files/file.php

class File extends CI_Model {

var $filename = '';

function __construct() {
parent::__construct();
}

// Return all config files
function get_files() {
$query = $this->db->get('config_files');
return $query->result();
}

function insert_file() {
$this->filename = $this->input->post('filename');
$this->db->insert('config_files', $this);
}

function update_file() {
$this->filename = $this->input->post('filename');
$this->db->update('config_files', $this, array('id' => $this->input->post('id'));
}
}

这是我的 Controller :位置:application/controllers/files/manage.php

管理类扩展 CI_Controller {

    function __construct() {
parent::__construct();
}

public function index() {
$this->load->model('files/file', TRUE);

$config_files['query'] = $this->File->get_files();

// Load the head section
$this->load->view('head');

// Load the view, passing in the data
$this->load->view('files/index', $configFiles);

// Load Footer
$this->load->view('footer');
}
}

在我的 View 中,我有一个简单的循环来显示结果:

  <?php foreach ($configFiles as $file) : ?>
<li><?php echo $file['filename'];?></li>
<?php endforeach;?>

最佳答案

尝试:

 $this->load->model('files/file','', TRUE);

编辑:

$data['configFiles'] = $this->File->get_files();
// Load the head section
$this->load->view('head');

// Load the view, passing in the data
$this->load->view('files/index', $data);

关于php - fatal error : Call to member function on a non-object Code Igniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7053517/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com