Welcome Guest, Not a member yet? Register   Sign In
Call to a member function userdata() on a non-object
#11

[eluser]why.you.and.i[/eluser]
Thank you for your reply Smile


I tried your suggestion but i got this error:
An Error Was Encountered
Unable to locate the model you have specified: hello_model


So i changed my model file name into application/models/hello_model.php (my previous file name was hello.php) and it works. Below is the example i was reading before and it didn't have "_model" when loading the model. Do models file must have "_model" in its name?


The example i was reading before: (http://ellislab.com/codeigniter/user-gui...odels.html)
Code:
class Blog_controller extends CI_Controller {

    function blog()
    {
        $this->load->model('Blog');

        $data['query'] = $this->Blog->get_last_ten_entries();

        $this->load->view('blog', $data);
    }
}
#12

[eluser]InsiteFX[/eluser]
And how and where did you save the model?

application/models/hello_model.php

InsiteFX
#13

[eluser]why.you.and.i[/eluser]
Yes, the fixed version was saved in application/models/hello_model.php. About the "_model" thing in the name i got it already, thank you for your time, i've pulling my hair half a day for this simple code [grin]
#14

[eluser]Carl Weis[/eluser]
I'm having the same issue, any help would be appreciated.

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;

I keep receiving the following error:
--------------------------------------------------------------------
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
#15

[eluser]InsiteFX[/eluser]
file is a php reserved word! Rename your Controller.

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB