donglv7097 2019-07-01 17:38
浏览 46

模型似乎没有加载 - 命名问题

In the process of upgrading from Codeigniter 2.2 to 3.1 we renamed all of the models. Now they are not loading unless I remake them with another name.

Looking at numerous other articles common issues are failing to load the model or typos in the names. I am not seeing either of these to be the case. There are several models who all have this issue, but a fix I found which is not ideal is making a new model with a new name. The first example is a model called PrpmsModel I can take everything in this file and make a new model called FooModel.php and just change the class name in the file to also be FooModel and then when I load it and make a call it works.

<?php
/**
 * PRPMS - Model
**/
if (! defined('BASEPATH'))
    exit('No direct script access allowed');

class PrpmsModel extends MY_Model
{

I took out the tail end but just to see top definition.

$this->load->model('PrpmsModel');
$employee = $this->PrpmsModel->fetchPRPMSbyEmployeeId(1, 1);

This does not work above.

<?php
/**
 * Foo - Model
**/
if (! defined('BASEPATH'))
    exit('No direct script access allowed');

class FooModel extends MY_Model
{

Copied all of PrpmsModel.php into FooModel.php

$this->load->model('FooModel');
$employee = $this->FooModel->fetchPRPMSbyEmployeeId(1, 1);

This above does work. The model used to be prpmsModel, so I just changed the case. The file name was also changed to match the PrpmsModel casing.

  • 写回答

1条回答 默认 最新

  • dryb38654 2019-07-02 02:06
    关注

    Naming conventions changed between CI 2.x and CI 3.x and are outlined in the 2.x->3.0 migration guide available HERE

    with specific regard to models, keep in mind that in CI 3:

    • File names should always be capitalized on the first character only (sales_model.php is NOT OK, neither is SALES_MODEL.php nor Sales_Model.php. Sales_model.php IS OK)
    • The model's class name must match the file name (using the previous example, your Class declaration should be Class Sales_model extends CI_Model { }
    • The model should be loaded in your controller using an all-lowercase name (so $this->load->model('sales_model'); IS OK, while $this->load->model('Sales_model');, $this->load->model('Sales_Model'); or $this->load->model('SALES_MODEL'); are not)

    Make sure everything in your migrated codebase adheres to the above conventions and you should be fine. If not, some more code (and also error/debug logs) would be needed to help you debug.

    Since you'll already be reviewing the 2.x->3.0 migration guide, take the time to review the whole document. A lot changed from 2.x to 3.x, so it definitely wouldn't hurt to make sure everything conforms to 3.x standards

    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制