Welcome Guest, Not a member yet? Register   Sign In
first noob question (models)
#1

[eluser]Xavier D.[/eluser]
Hi,

I just started 2 hours ago with ci, it seems to be a great platform.

I've already tested several things, but now i'm having troubles with models.

Code:
<?php
// controller

class Test extends Controller {

    function Test()
    {
        parent::Controller();
        $this->load->scaffolding('cld');    
    }
    
    function index()
    {
        $this->load->model('Test_model');
        $data['query'] = $this->Test_model->get_cld();
        $data['title']      = "Welcome bij cld";
        $data['heading'] = "Eerste ci project";
        $data['message'] = "Ci lijkt me een heel interessant gegeven :)";
        $this->load->view('includes/header', $data);
        //$this->load->view('test_view', $data);
        $this->load->view('test_view', $data);
        $this->load->view('includes/footer');
    }
}
?>
<?php
// models

class Test_model extends Model {

        var $title   = '';
        var $message = '';
        var $date    = '';

        function Test_model()
        {
            // Call the Model constructor
            parent::Model();
        }
    
        function get_cld()
        {
            $query = $this->db->get('cld');
            return $query->result();
        }
    }
?>

//view

<h1>&lt;?php echo $title ?&gt;</h1>
<p>&lt;?php echo $message ?&gt;</p>
&lt;?php foreach($query->related as $row): ?&gt;

<h3>&lt;?=$row->title?&gt;</h3>
<p>&lt;?=$row->message?&gt;</p>
<p>Datum: &lt;?=$row->date?&gt;</p>

&lt;?php endforeach;?&gt;

What am i doing wrong, calling the database in the controller works fine, but the moment i want to use modelsthe problem started ..

Also scaffolding is working fine.

error: Call to a member function get() on a non-object in /home/***/domains/***/public_html/cld/system/application/models/test_model.php on line 15


Messages In This Thread
first noob question (models) - by El Forum - 08-08-2008, 05:56 AM
first noob question (models) - by El Forum - 08-08-2008, 06:15 AM
first noob question (models) - by El Forum - 08-08-2008, 06:18 AM
first noob question (models) - by El Forum - 08-08-2008, 06:27 AM
first noob question (models) - by El Forum - 08-08-2008, 06:28 AM
first noob question (models) - by El Forum - 08-08-2008, 06:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB