【问题标题】:Unable to locate the specified class: Model.php codeigniter phpstorm找不到指定的类:Model.php codeigniter phpstorm
【发布时间】:2015-05-11 13:41:14
【问题描述】:

我正在尝试为 codeigniter 添加 phpstorm 自动完成功能,如在不同问题中所见。

提供的链接:https://github.com/topdown/phpStorm-CC-Helpers

我注释掉了指定的文件并添加了

* @property Test_model      $test_model

my_models.php

当我尝试从我的控制器加载Test_model.php 时:

$this->load->model('Test_model');

我明白了:

'找不到指定的类:Model.php'

如果我删除加载行并尝试:

$this->Test_model->insert_entry()

我明白了:

消息:未定义的属性:Test::$Test_model

Test.php:

class Test extends CI_Controller {
  public function __construct(){
        parent::__construct();
  }
  public function modelTutorial(){
    $this->Test_model->insert_entry();
 }

Test_model.php

class Test_model extends CI_Model{

  public function __construct(){
      parent::__construct();
  }

  public function insert_entry(){
      die('asdasd');
  }
}

【问题讨论】:

    标签: php codeigniter model phpstorm


    【解决方案1】:

    创建模型时,需要将文件放在application/models/中,并将文件命名为lowercase——如yourfile_model.php

    将您的文件名从 Test_model 更改为 test_model.php 并在控制器构造函数中调用它

    public function __construct(){
            parent::__construct();
            $this->load->model('test_model');
      }
    

    阅读手册Models

    【讨论】:

    • codeigniter 教程列出了第一个字母大写的模型文件。我尝试将文件名设置为小写:test_model,仍然相同的错误(无法找到指定的类:Model.php)...查看:codeigniter.dev/user_guide/general/models.html
    • 它的类名okk在类名的第一个字母是大写
    • Model_name 是您的班级名称。类名的第一个字母必须大写,其余部分小写。确保您的类扩展了基础模型类。文件名将是您的类名的小写版本。例如,如果你的班级是这样的:
    • 文件名将是你的类名的小写版本
    • 无论文件名的首字母大小写如何,我都可以使用 $this->load->model('test_model') 获取模型,问题是当我尝试为 phpstorm 添加自动完成功能时获取无法找到指定的类:Model.php。 pulgin 指令是注释掉 system/core/Model.php
    猜你喜欢
    • 2013-11-27
    • 2017-06-21
    • 2015-08-01
    • 2017-05-29
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-28
    相关资源
    最近更新 更多