CakePHP Table Naming Convention

I have an existing site in Joomla. and I want a new application in CakePHP, but with the same existing Joomla database.

So here is the problem with the name of the tables. Please suggest me to use this table (for example market_type, listing_typein the singular form) in CakePHP, because the standard CakePHPwe use the table in the plural.

+3
source share
4 answers

You can define the table name in the model

class Example extends AppModel {
public $useTable = 'exmp'; // This model uses a database table 'exmp'
}

Use Table Cakephp

+7
source

You can also add custom rules to the inflector. This way the baker will also understand your table names.

// somewhere in your bootstrap.php
Inflector::rules('plural', array('irregular' => array('singular' => 'plural')));
+2
source

Inflector classify() tableize(), , Cake / . :

    $model = Inflector::classify('market_type');

    MarketType

.

, :

    Inflector::tableize('MarketType');

    market_types

.

Inflector CakePHP, . : CakePHP 2.x: Inflector

Cake, .

+2

( ):

public $useTable = 'tablename';

cakePhp , .

0

All Articles