问题
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