You can direct access Model page from View page in Codeigniter.
First, you need to check if you model class name have in parent::__construct(). If you can’t define Model class name then do it first. For example:
public function __construct(){
parent::__construct();
$this->load->helper(‘url’);
$this->load->helper(‘form’);
// Model
$this->load->model(‘Model Classs Name Here’);
}
Now you can access model from you view page. Like
<?php
$this->MyModel->SearchResult(); // MyModel is the Model class name and SearchResult is user define function name.
?>
If you want to pass some value from your view page, then follow this code.
<?php
$id=$val->user_id;
$this->MyModel->GetUser($id);
?>
I hope it will be helpful for you.
Question and answer is powered by AnsPress.io