在Doctrine 2.2 + CodeIgniter 2.1中找不到类模型 [英] Class Model not found in Doctrine 2.2 + CodeIgniter 2.1

查看:182
本文介绍了在Doctrine 2.2 + CodeIgniter 2.1中找不到类模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在CodeIgniter 2.1和Doctrine 2.2上设置了一个项目,按照
Doctrine 食谱。 EntityManager工作,但是当我尝试加载实体模型时,
给我错误

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 

这是我的home.php文件:

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'); ,然后
它完美地工作。

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

如何使模型自动加载?

How can I make the models auto-loaded?

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

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.

推荐答案

我猜你的User.php文件中有一个命名空间行?

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

如果是,那么你将需要在控制器代码中添加一个使用语句,因此php命名空间系统知道在哪里查找您的实体。

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.

如果不是,则验证您的entityClassLoader实际上是被调用,并且APPPATH具有预期值。

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

这篇关于在Doctrine 2.2 + CodeIgniter 2.1中找不到类模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆