• 0

Problems using a model in MVC


Question

I made a small framework where I have a problem linking the model to the controller.

The error: Call to undefined function Milkey\Controllers\test()

 

This is my controller class:

<?php

namespace Milkey\Core;

class Controller {

    public $language;
    public $view;

    public function __construct() {
        $this->language = new Language();
        $this->view = new View();
    }

}

My model class:

<?php

namespace Milkey\Core;

class Model extends \Milkey\Core\Controller {

    protected $_db;

    public function __construct() {
        parent::__construct();

        $this->_db = new Database();
    }

}

And my model that I want to use in my controller:

<?php

namespace Milkey\Models;

class Login extends \Milkey\Core\Model {

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

    public function test() {
        return 'yes';
    }

}

So now, in my LoginController, where do I put this to use this model? $this->model->test(); does not work.

<?php

namespace Milkey\Controllers;

class LoginController extends \Milkey\Core\Controller {

    public function __construct() {
        parent::__construct();

        $this->language->load('login');
    }

}

Anybody who could explain me what I am doing wrong? Thank you.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

A model is a model, a model is not a controller. Why therefore is your base model class extending your base controller class?

 

How can anyone really tell you what you're doing wrong when you're using a custom built framework and you've not supplied the code for it rolleyes.gif

Link to comment
Share on other sites

  • 0

A model is a model, a model is not a controller. Why therefore is your base model class extending your base controller class?

 

I overlooked that one. Thank you for noticing.

 

I think someone needs to read a guide to basic MVC principles... :)

 

I am just learning. But thank you for the positive feedback.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.