What is the correct practice to incorporate models?
I am trying to simplify the process of inserting data into my database, so I have constructed a model that h开发者_运维问答andles the variable extraction and data inserting.
I understand that this model embodies a function, and then you call this function (such as /controller/model) and pass the relevant data through the model for processing. However, I am unsure how to incorporate the model, whereas how to call it, or what needs to be written so I can call the function out. I am using CodeIgniter.
Here's the said model:
class Createproject extends ActiveRecord {
function __insert() // This function will handle inserting the relevant project information into the database.
{
$this->project_name = $this->input->get_post('project_name');
// ... skipping ~30 variable definitions ...
$this->db->insert('project_details', $this);
}
So I'm confused from here; where do you place this model for processing, and how would you use it within controllers or the rest of the app?
Thanks!
You can just import (require_once) it into your controller (save it into models.php), and instantiate it in your controller:
$cp = new Createproject()
$cp->__insert()
精彩评论