-2

At this time I start to build a MVC framework (PHP). Everything is going fine but now I got a problem :

Notice: Undefined property: welcome::$users in C:\wamp\www\framework\application\controllers\welcome.php on line 17

this is the second error

Fatal error: Call to a member function member() on a non-object in C:\wamp\www\framework\application\controllers\welcome.php on line 17

this is my model

class users extends Model {

function __construct() {
    $this->db_type = new mysql_database();
}

public function member(){

}

}

this is my controller

class welcome extends Controller{

public function index(){
    $this->model('users');
    $this->users->member();
}

}

this is my base controller

abstract class Controller {

public function model($model_name) {
    $model_path = APP_PATH . 'models' . '/' . $model_name . EXT;
    if (file_exists($model_path)) {
        require_once $model_path;
        if (class_exists($model_name))
            $model_name = new $model_name();
        return $model_name;
    }
}

}

what is the solution of this error thanks

tereško
  • 58,060
  • 25
  • 98
  • 150
user1095615
  • 15
  • 1
  • 3

1 Answers1

0

Sets a property with the name of the model with its respective value, an instance of the class.

if (class_exists($model_name))
    $model = new $model_name();
    $this->{$model_name} = $model;