Kohana 3.2: Calling model with underscore in name

安稳与你 提交于 2019-12-13 02:33:40

问题


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();

It can't find my model. Within my model file, the class is named exactly the same way (Model_Class_User).

Does Kohana not like model names with underscores?


回答1:


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.

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

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';
}


来源:https://stackoverflow.com/questions/10018396/kohana-3-2-calling-model-with-underscore-in-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!