在 Doctrine 2.2 中找不到类模型 +代码点火器2.1

发布于 2025-01-07 16:06:13 字数 1155 浏览 2 评论 0原文

我已经按照 CodeIgniter 2.1 和 Doctrine 2.2 建立了一个项目,遵循 教义食谱。 EntityManager 可以工作,但是当我尝试加载实体模型时,它 给我错误

Fatal error: Class 'Users' not found in /Volumes/Data/Projects/myproject/application/controllers/home.php on line 10 

This is my home.php file:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

//require_once(APPPATH.'models/Users.php');

class Home extends CI_Controller {
  public function index()
  {
    $em = $this->doctrine->em;
    $users = new Users;     
    //$user = $em->find("Users", 1);
    $em->flush(); // dummy
    $this->load->view('welcome_message');
  }
}

如果我取消注释第 3 行: require_once(APPPATH.'models/Users.php');,那么 它工作得很好。

如何让模型自动加载?

自动加载机制是由libraries/ Doctrine.php 中的引导程序处理的,不是吗?

    $entitiesClassLoader = new ClassLoader('models', rtrim(APPPATH, "/" )); 
    $entitiesClassLoader->register(); 

请任何人给我关于这个问题的见解。

I have set up a project with CodeIgniter 2.1 and Doctrine 2.2, following the instruction on
Doctrine cookbook. The EntityManager works, but when I try to load entity models, it
gives me error

Fatal error: Class 'Users' not found in /Volumes/Data/Projects/myproject/application/controllers/home.php on line 10 

This is my home.php file:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

//require_once(APPPATH.'models/Users.php');

class Home extends CI_Controller {
  public function index()
  {
    $em = $this->doctrine->em;
    $users = new Users;     
    //$user = $em->find("Users", 1);
    $em->flush(); // dummy
    $this->load->view('welcome_message');
  }
}

If I uncomment line 3: require_once(APPPATH.'models/Users.php');, then
it works perfectly.

How can I make the models auto-loaded?

Is the autoload mechanism handled by the bootstrap in libraries/ Doctrine.php, isn't it?

    $entitiesClassLoader = new ClassLoader('models', rtrim(APPPATH, "/" )); 
    $entitiesClassLoader->register(); 

Please anyone give me insight about this issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奶气 2025-01-14 16:06:13

我猜您的 Users.php 文件中有一个名称空间行?

如果是这样,那么您需要在控制器代码中添加“use”语句,以便 php 命名空间系统知道在哪里查找您的实体。

如果没有,则验证您的EntityClassLoader是否确实被调用并且APPPATH具有预期值。

I'm guessing that you have a namespace line inside of your Users.php file?

If so then you will need to add a "use" statement to your controller code so the php namespace system knows where to look for your entities.

If not then verify that your entitiesClassLoader is actually being called and that APPPATH has the expected value.

往事风中埋 2025-01-14 16:06:13

我从未使用过 CI 和 Doctrine,所以不知道 Doctrine 是否应该加载模型或加载模型的位置,但你应该尝试自己做,不是使用包含,而是这样:

在控制器中:
$this->load->model('Users');

或者作为 application/config/autoload.php 中的 Autoload 并将模型加载到数组中。

I've never worked with CI and Doctrine so don't know if Doctrine should load the models or where it loads them, but you should try to do it yourselft, not with an include but this way :

In the Controller :
$this->load->model('Users');

Or as Autoload in application/config/autoload.php and load the model in the Array.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文