Welcome Guest, Not a member yet? Register   Sign In
Fatal Error: Call to member function on a non-object.
#1

[eluser]Carl Weis[/eluser]
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

Code:
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
Code:
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:
Code:
<?php foreach ($configFiles as $file) : ?>
        <li>&lt;?php echo $file['filename'];?&gt;</li>
  &lt;?php endforeach;?&gt;
#2

[eluser]OliverHR[/eluser]
check case on word file at this line:

Code:
config_files['query'] = $this->file->get_files();
#3

[eluser]Carl Weis[/eluser]
I changed it to lowercase and it still produces the same error.

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Manage::$files

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
#4

[eluser]Carl Weis[/eluser]
Is there a way to make sure Code Igniter is connecting to my database?
#5

[eluser]Bart v B[/eluser]
Where is $configFiles comming from?

Code:
class Manage extends CI_Controller {

        function __construct() {
            parent::__construct();
            $this->load->database();
        }

        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', $config_files);

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


view file:

Code:
&lt;?php foreach ($query as $file) : ?&gt;
        <li>&lt;?php echo $file['filename'];?&gt;</li>
  &lt;?php endforeach;?&gt;
#6

[eluser]InsiteFX[/eluser]
Message: Undefined property: Manage::$File

file is a php reserved word!

$config_files is being passed to the view as data just like $data!
Code:
&lt;?php foreach ($configFiles as $file) : ?&gt;
    <li>&lt;?php echo $query;?&gt;</li>
&lt;?php endforeach;?&gt;

InsiteFX
#7

[eluser]OliverHR[/eluser]
[quote author="InsiteFX" date="1313297366"]Message: Undefined property: Manage::$File

file is a php reserved word!

$config_files is being passed to the view as data just like $data!
Code:
&lt;?php foreach ($configFiles as $file) : ?&gt;
    <li>&lt;?php echo $query;?&gt;</li>
&lt;?php endforeach;?&gt;
[/quote]


Actually __FILE__ is a predefined constants but not $file.
#8

[eluser]InsiteFX[/eluser]
Oh really!

PHP.net

Code:
array file ( string $filename [, int $flags = 0 [, resource $context ]] )

Look at his model Class Name!

InsiteFX
#9

[eluser]Aken[/eluser]
This is not an issue of a reserved name - I was able to create a model called File no problem.

You're loading the model incorrectly. If you're trying to use the auto connect to DB parameter, you need to include a blank second parameter first.
Code:
$this->load->model('files/file', '', TRUE);
#10

[eluser]OliverHR[/eluser]
[quote author="InsiteFX" date="1313365394"]Oh really![/quote]

Yes really:

http://php.net/manual/en/reserved.php

http://www.php.net/manual/en/reserved.keywords.php




Theme © iAndrew 2016 - Forum software by © MyBB