Reputation: 7042
I followed the documentation on Models and I keep getting this error, any help would be appreciated.
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Manage::$File
Filename: files/manage.php
Line Number: 14
Fatal error: Call to a member function get_files() on a non-object in /var/www/uisimulator/application/controllers/files/manage.php on line 14*
Here is my Model: - Located: 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'));
}
}
Here is my Controller: Location: application/controllers/files/manage.php
class Manage extends 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');
}
}
Inside my view I have a simple loop to show the results:
<?php foreach ($configFiles as $file) : ?>
<li><?php echo $file['filename'];?></li>
<?php endforeach;?>
Upvotes: 0
Views: 17011
Reputation: 21
This code result one record, but give me only fields from one table.
function listar_dados_produto($id)
{
$this->db->where('id',$id);
$query = $this->db->get('produtos');
return $query->result();
}
Note: I am using activerecord. The table produtos return their fields corectly, but i need one field for another table named categorias.
Upvotes: 1
Reputation: 17967
Any reason you have passed TRUE
as the second parameter in the $this->load->model
method?
My understanding with CI is that the second parameter is to refer to your model by a different name, other than it's class.
It would appear you are naming your class a boolean, which is bound to cause some kind of error.
Try:
$this->load->model('files/file', NULL, TRUE);
//$data['configFiles'] = $this->File->get_files();
print_r($this->File->get_files());
exit;
// do you get any data?
// Load the head section
$this->load->view('head');
// Load the view, passing in the data
$this->load->view('files/index', $data);
Upvotes: 0
Reputation: 2247
Try:
$this->load->model('files/file','', TRUE);
EDITED:
$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);
Upvotes: 2