Welcome Guest, Not a member yet? Register   Sign In
Database MVC seperation problems (beginners question)
#1

[eluser]Slowcheetah[/eluser]
I'm new to OOP, MVC and CodeIgniter. I'm having problems to learn the MVC coding principles. A simple question;

Why this code IS working;

MODEL
Code:
<?php
class Startpagina_Model extends Model {

    function Startpagina_Model()
    {
        // Call the Model constructor
        parent::Model();
        
    }
    
    function Overzicht_Competities()
    {
        $query = $this->db->query('SELECT id, name FROM game_competitions');
        
        foreach ($query->result() as $row)
        {
            echo $row->name;

        }
        
    }
    
}

/* End of file startpagina_model.php */
/* Location: ./system/application/models/startpagina_model.php */

CONTROLLER

Code:
<?php

class Startpagina extends Controller {

    function __construct()
    {
        parent::Controller();
    }


    function index()
    {
        $this->load->model('startpagina_model');
    
        $data['query'] = $this->startpagina_model->Overzicht_Competities();
    
        $this->load->view('startpagina', $data);
    }

}

/* End of file startpagina.php */
/* Location: ./system/application/controllers/startpagina.php */

And this code IS NOT working?

MODEL
Code:
<?php
class Startpagina_Model extends Model {

    function Startpagina_Model()
    {
        // Call the Model constructor
        parent::Model();
        
    }
    
    function Overzicht_Competities()
    {
        $query = $this->db->query('SELECT id, name FROM game_competitions');
        
    }
    
}

/* End of file startpagina_model.php */
/* Location: ./system/application/models/startpagina_model.php */


VIEW

Code:
<html>
<head>
<title>test</title>
</head>
<body>


<?php

foreach ($query->result() as $row)
{
    echo $row->name;
}

?>


</body>
</html>

CONTROLLER

Code:
<?php

class Startpagina extends Controller {

    function __construct()
    {
        parent::Controller();
    }


    function index()
    {
        $this->load->model('startpagina_model');
    
        $data['query'] = $this->startpagina_model->Overzicht_Competities();
    
        $this->load->view('startpagina', $data);
    }

}

/* End of file startpagina.php */
/* Location: ./system/application/controllers/startpagina.php */


Messages In This Thread
Database MVC seperation problems (beginners question) - by El Forum - 03-02-2009, 08:06 PM
Database MVC seperation problems (beginners question) - by El Forum - 03-02-2009, 08:13 PM
Database MVC seperation problems (beginners question) - by El Forum - 03-02-2009, 08:15 PM
Database MVC seperation problems (beginners question) - by El Forum - 03-02-2009, 08:19 PM
Database MVC seperation problems (beginners question) - by El Forum - 03-02-2009, 08:21 PM
Database MVC seperation problems (beginners question) - by El Forum - 03-02-2009, 08:49 PM
Database MVC seperation problems (beginners question) - by El Forum - 03-02-2009, 09:37 PM
Database MVC seperation problems (beginners question) - by El Forum - 03-02-2009, 09:50 PM
Database MVC seperation problems (beginners question) - by El Forum - 03-02-2009, 09:54 PM
Database MVC seperation problems (beginners question) - by El Forum - 03-03-2009, 12:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB