Can you use underscores in table names as part of the Kohana PHP framework (and how)?

The underscore is a special character in Kohana and translates to a directory delimiter, but since I have a bunch of existing code that uses underscores in table names, I want to know if Kohana can be configured to figure it out somehow.

+3
source share
4 answers

One way to do this is to place model classes in subdirectories of the Model folder.

For example, if you have a table with a name user_profiles, your directories will look like this:

application/
...classes/
......model/
.........user/
............profile.php

and profile.phpwill look like this:

<?php defined('SYSPATH') or die('No direct access.');

class Model_User_Profile extends ORM 
{
}

( , ), "" , . , - , _table_name ORM (. Docs )

application/
...classes/
......model/
.........userprofile.php

profile.php :

<?php defined('SYSPATH') or die('No direct access.');

class Model_UserProfile extends ORM 
{
    protected $_table_name = 'user_profiles'; // <== manually setting table name
}

, , Kohana.

+4

Kohana . , , ($this->db->query($sql)), Builder Builder ($this->from($table_name)->...->execute()) AR ( ORM > , , - table_name). , ( ), notJim.

+1

, . , $_table_name model.

class Model_Profile extends ORM
{
    protected $_table_name = 'user_profiles';
}
0

, . - , pluralized . ,

Model_Foo_Bar {
}

foo_bars , Kohana .

0

Source: https://habr.com/ru/post/1763550/


All Articles