Kohana 3.2:名称中带有下划线的调用模型 [英] Kohana 3.2: Calling model with underscore in name
问题描述
我有以下模型:在我的数据库clas_user中的一个表后命名了class_user.当我使用以下代码调用此模型时:
I have the following model: class_user nammed after a table in my database clas_user. When I call this model with the following code:
$class_user = new Model_Class_User();
找不到我的模型.在我的模型文件中,该类的命名方式完全相同(Model_Class_User).
It can't find my model. Within my model file, the class is named exactly the same way (Model_Class_User).
Kohana不喜欢带下划线的型号名称吗?
Does Kohana not like model names with underscores?
推荐答案
下划线直接反映了您应用中文件的位置.这意味着您的Class_User
模型文件应位于application/classes/model/class/user.php
Underscores directly reflect the file location in your app. Meaning your Class_User
model file should be located in application/classes/model/class/user.php
文件名中不应包含下划线.
The file name should not have an underscore in it.
以下是一些链接,以了解Kohana约定和级联文件系统.
http://kohanaframework.org/3.2/guide/kohana/conventions
http://kohanaframework.org/3.2/guide/kohana/files
Here are some links to learn about Kohana conventions and the cascading file system.
http://kohanaframework.org/3.2/guide/kohana/conventions
http://kohanaframework.org/3.2/guide/kohana/files
还要查看 http://kohanaframework.org/3.2/guide/orm/models了解ORM.您会立即注意到,由于表具有非常规名称,因此需要创建$_table_name
变量.下面提供了示例.
Also look at http://kohanaframework.org/3.2/guide/orm/models to learn about ORM. You'll notice right away that you'll need to create a $_table_name
variable because your table has an unconventional name. Example provided below.
class Model_Class_User extends ORM {
protected $_table_name = 'class_user';
}
这篇关于Kohana 3.2:名称中带有下划线的调用模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!