错误:(application\models/projects/It_project_companies.php存在,但没有声明类It_project_companies),当我试图保存一个项目时发生。我正在从控制器加载保存方法中的模型:
public function addProject()
{
$input = $this->input->post(null, true);
if ($this->validateFields($input)) {
$this->load->model('projects/it_projects_notifiers');
$this->load->model('projects/it_project_companies'); //my model
$projectData = [
'title' => $input['project_subject'],
'description' => $input['project_details'],
'creator' => $_SESSION['UserID'],
'affected' => $input['affected_id'],
'assignee' => $input['project_responsible'],
'priority' => $input['project_priority'],
'type' => $input['project_type'],
'created' => date('Y-m-d H:i:s'),
'company' => $input['project_companies'],//$project_company,
'start_date' => date('Y-m-d', strtotime($input['project_start_date'])),
'end_date' => date('Y-m-d', strtotime($input['project_end_date'])),
'estimated' => ($input['project_estimated_days'] * 24 + $input['project_estimated_hours']),
];
if ($this->db->insert('it_projects', $projectData)) {
$projectID = $this->db->insert_id();
$this->it_project_companies->addCompanies($projectID, $input['project_companies']);
$this->it_projects_notifiers->add_notifiers_affected($projectID, $input['affected_id']);
$this->it_projects_notifiers->add_notifiers($projectID, $input['project_notifiers']);
// add files ...
$this->uploadFiles($_FILES, $projectID);
$this->load->model('projects/it_projects_notifications');
$this->it_projects_notifications->send_notifications('new_project', 0, $projectID, $_FILES);
}
}
}
和addCompanies方法:
class It_project_companies extends \My_Model
{
public function __construct()
{
parent::__construct();
}
public function addCompanies($projectID, $companyIDs) {
foreach ($companyIDs as $companyID) {
$projectCompanyData = [
'project_id' => $projectID,
'company_id' => $companyID,
];
$this->db->insert('it_project_companies', $projectCompanyData);
}
}
}
我必须补充的是,目前我没有查询连接所需的表等...因为我不知道如何使他们和错误仍然发生时,我有查询,可能写错了...
2条答案
按热度按时间vbopmzt11#
我的解决方案是删除名称空间,因为composer.json中没有自动加载,我不知道使用
$this->load->model()
加载模型是否是一种好方法,或者我应该使用Composer自动加载类。f3temu5u2#
我不知道为什么My_Model前面有一个“/”