Reputation: 45
I have an existing site in Joomla
. and I want new application in CakePHP
but with same existing Joomla site database.
So here is the problem with the tables name. Please suggest me how to use that table (like market_type
, listing_type
in singular form) in Cakephp
, because in cakephp
standard we use tables in plural form.
Upvotes: 4
Views: 1489
Reputation: 685
You can bind your any table with using the model(in which you want to use that table) :
But in cakePhp table name convention is plural of model name to make a relation implicitely..
Upvotes: 0
Reputation: 75
you can also always use Inflector's methods classify() and tableize() to find out what Cake would expect as a table names/model names for a given model. A simple reverse-engineering of your example shall explain this:
$model = Inflector::classify('market_type');
which would give you
MarketType
as the expected model name.
The table name therefore is:
Inflector::tableize('MarketType');
which gives
market_types
for the first mentioned table in your scenario.
The Inflector-class has many useful methods when working with strings in CakePHP, see the documentation here: CakePHP 2.x: Inflector
These are in fact the correct names by Cake's conventions, and I would highly recommend sticking to that when using the framework.
Upvotes: 2
Reputation: 324
You could also add custom rules to the inflector. This way the baker will understood your table names, too.
// somewhere in your bootstrap.php
Inflector::rules('plural', array('irregular' => array('singular' => 'plural')));
Upvotes: 2
Reputation: 1577
You can define table name in model
class Example extends AppModel {
public $useTable = 'exmp'; // This model uses a database table 'exmp'
}
Upvotes: 9