cakephp-1.3 > Model :: __construct()
A AclBase AclBehavior AclComponent AclNode AclShell Aco AcoAction AjaxHelper ApcEngine ApiShell App AppController AppController AppHelper AppHelper AppModel AppModel Aro AuthComponent B BakeShell BakeTask BehaviorCollection C Cache CacheEngine CacheHelper CakeErrorController CakeLog CakeRoute CakeSchema CakeSession CakeSocket ClassRegistry Component Configure ConnectionManager ConsoleShell ContainableBehavior Controller ControllerTask CookieComponent D DataSource DbAcl DbAclSchema DbConfigTask DboMssql DboMysql DboMysqlBase DboMysqli DboOracle DboPostgres DboSource DboSqlite Debugger Dispatcher E EmailComponent ErrorHandler ErrorHandler ExtractTask F File FileEngine FileLog FixtureTask Folder FormHelper H Helper HtmlHelper HttpSocket I I18n I18nModel i18nSchema I18nShell Inflector IniAcl J JavascriptHelper JqueryEngineHelper JsBaseEngineHelper JsHelper L L10n M MagicDb MagicFileResource MediaView MemcacheEngine Model ModelBehavior ModelTask MootoolsEngineHelper Multibyte N NumberHelper O Object Overloadable Overloadable Overloadable2 Overloadable2 P PagesController PagesController PaginatorHelper Permission PluginShortRoute PluginTask ProjectTask PrototypeEngineHelper R RequestHandlerComponent Router RssHelper S Sanitize Scaffold ScaffoldView SchemaShell Security SecurityComponent SessionComponent SessionHelper SessionsSchema Set Shell ShellDispatcher String T TemplateTask TestSuiteShell TestTask TextHelper ThemeView TimeHelper TranslateBehavior TreeBehavior V Validation View ViewTask X XcacheEngine Xml XmlElement XmlHelper XmlManager XmlNode XmlTextNode

__construct

line:403 at /cake/libs/model/model.php
Constructor. Binds the model's database table to the object.

Method

__construct ($id = false, $table = null, $ds = null)

Parameters

ParameterTypeCommentDefault
$id mixed optional Set this ID for this model on startup, can also be an array of options, see above. false
$table string optional Name of database table to use. null
$ds string optional DataSource connection name. null

Return

Comment

Constructor. Binds the model's database table to the object.

If `$id` is an array it can be used to pass several options into the model.

- id - The id to start the model on.
- table - The table to use for this model.
- ds - The connection name this model is connected to.
- name - The name of the model eg. Post.
- alias - The alias of the model, this is used for registering the instance in the `ClassRegistry`.
eg. `ParentThread`

### Overriding Model's __construct method.

When overriding Model::__construct() be careful to include and pass in all 3 of the
arguments to `parent::__construct($id, $table, $ds);`

### Dynamically creating models

You can dynamically create model instances using the $id array syntax.

{{{
$Post = new Model(array('table' => 'posts', 'name' => 'Post', 'ds' => 'connection2'));
}}}

Would create a model attached to the posts table on connection2. Dynamic model creation is useful
when you want a model object that contains no associations or attached behaviors.

@param mixed $id Set this ID for this model on startup, can also be an array of options, see above.
@param string $table Name of database table to use.
@param string $ds DataSource connection name.