Kohana 3自动加载模型 [英] Kohana 3 Auto loading Models

查看:56
本文介绍了Kohana 3自动加载模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用模型,但出现致命错误,因此我认为它无法正确自动加载.

I'm attempting to use a Model but I get a fatal error so I assume it doesn't autoload properly.

ErrorException [致命错误]:类 找不到"Properties_Model"

ErrorException [ Fatal Error ]: Class 'Properties_Model' not found

有问题的控制器行:

$properties = new Properties_Model;

模型:

class Properties_Model extends Model
{
    public function __construct()
    {
          parent::__construct();
    }

}

我还把班级放在三个不同的地方,希望一个地方能工作,但都失败了. 他们是: 应用程序/类/模型 应用/型号 应用程序/模型

I also put the class in three different locations hoping one would work, all there failed. They are: application/classes/model application/model application/models

我想念什么?

推荐答案

啊,我收到了直接通过我的网站联系表通过电子邮件发送给我的问题!

Ah, I got this question emailed directly to me (via my website's contact form)!

这是我的答复(为了可能会遇到此问题的其他人的利益).

Here is what I responded with (for the benefit of other people which may run into this problem).

名为的模型的正确位置 properties

The correct location of a model named properties is

application/classes/model/properties.php

,并且类定义为 跟随

and the class definition would be as follows

class Model_Properties extends Model { }

将上面的下划线视为 目录分隔符.也就是说,如果你 用/您替换了下划线 将具有:模型/属性",其中 将是您在application/classes下的文件.

Think of the underscore above as the directory separator. That is, if you replaced the underscore with a / you would have: 'model/properties', which will be your file under application/classes.

要从控制器加载模型, 您可以使用PHP的标准新功能 运算符或执行我喜欢的操作,这是

To load the model from a controller, you can use PHP's standard new operator or do what I prefer, which is

$propertiesModel = Model::factory('Properties');

我不是100%为什么喜欢这种方式... 但这对我有用:)

I'm not 100% why I prefer this way... but it works for me :)

这篇关于Kohana 3自动加载模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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