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

[eluser]xwero[/eluser]
Is the active record setting in the config/database.php true?
#3

[eluser]Xavier D.[/eluser]
Thx for the fast reply,

the AR is set to true

$active_record = TRUE;

Code:
$query = $this->db->query('select * from cld');

in the models page(same problem)

error: Call to a member function query() on a non-object
#4

[eluser]Xavier D.[/eluser]
Problem solved.

$autoload['libraries'] = array();

must be

$autoload['libraries'] = array('database');
#5

[eluser]xwero[/eluser]
try this
Code:
$this->load->model('Test_model','',TRUE);
#6

[eluser]Xavier D.[/eluser]
[quote author="xwero" date="1218216514"]try this
Code:
$this->load->model('Test_model','',TRUE);
[/quote]

Is also working, there was a load problem then.

thx for the support




Theme © iAndrew 2016 - Forum software by © MyBB