合并模型的正确做法是什么?
我试图简化将数据插入数据库的过程,因此我构建了一个模型来处理变量提取和数据插入。
我理解这个模型体现了一个函数,然后你调用这个函数(比如/controller/model),通过模型传递相关数据进行处理。但是,我不确定如何合并模型,以及如何调用它,或者需要编写什么才能调用该函数。我正在使用 CodeIgniter。
这是所说的模型:
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);
}
所以我从这里感到困惑;您将该模型放在哪里进行处理,以及如何在控制器或应用程序的其余部分中使用它?
谢谢!
I am trying to simplify the process of inserting data into my database, so I have constructed a model that handles 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需将其导入(require_once)到控制器中(将其保存到 models.php 中),然后在控制器中实例化它:
You can just import (require_once) it into your controller (save it into models.php), and instantiate it in your controller: