Null model on controller route
Closed this issue · 2 comments
vincenzocasu commented
Hi, i have generated model, view And controller by usino wpmcv command Line tool.
In The controller using $this->Model->find() method i getto fatal error: Call To A member function find() on null in ...
Where is The fault?
vincenzocasu commented
public function show() {
$users_model = mvc_model('Users');
$object = $users_model->find_by_ID($this->params['id_user']);
if (!empty($object)) {
$this->set('data', $object);
}else{
$this->set('data', $this->params);
}
}
This works! But $this->model
is always null... when can(/do) i use $this->model->{method}
?
nhatnx commented
Model name must be in singular form. Your model name and file must be "User" and "user.php".
If you would like to use "Users" as your model, you can add $this->model = mvc_model('Users');
in controller constructor.