CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.6 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.6
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
      • Validator
    • Network
      • Email
      • Http
    • Routing
      • Filter
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

  • BakeTask
  • CommandTask
  • ControllerTask
  • DbConfigTask
  • ExtractTask
  • FixtureTask
  • ModelTask
  • PluginTask
  • ProjectTask
  • TemplateTask
  • TestTask
  • ViewTask

Class ModelTask

Task class for creating and updating model files.

AppShell
Extended by BakeTask
Extended by ModelTask
Package: Cake\Console\Command\Task
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/Console/Command/Task/ModelTask.php

Properties summary

  • $_modelNames protected
    array
    Holds the model names
  • $_tables protected
    array
    Holds tables found on connection.
  • $_validations protected
    array
    Holds validation method map.
  • $path public
    string
    path to Model directory
  • $skipTables public
    array
    Tables to skip when running all()
  • $tasks public
    array
    tasks

Inherited Properties

  • connection, interactive, plugin

Method Summary

  • _generatePossibleKeys() protected
    Finds all possible keys to use on custom associations.
  • _getModelObject() protected
    Get a model object for a class name.
  • _interactive() protected
    Handles interactive baking
  • _printAssociation() protected
    Print out all the associations of a particular type
  • all() public
    Bake all models at once.
  • bake() public
    Assembles and writes a Model file.
  • bakeFixture() public
    Interact with FixtureTask to automatically bake fixtures when baking models.
  • bakeTest() public
    Assembles and writes a unit test file
  • confirmAssociations() public
    Interact with the user and confirm associations.
  • doActsAs() public
    Handles behaviors
  • doAssociations() public
    Handles associations
  • doMoreAssociations() public
    Interact with the user and generate additional non-conventional associations
  • doValidation() public
    Handles Generation and user interaction for creating validation.
  • execute() public
    Execution method always used for tasks
  • fieldValidation() public
    Does individual field validation handling.
  • findBelongsTo() public
    Find belongsTo relations and add them to the associations list.
  • findDisplayField() public
    interact with the user to find the displayField value for a model.
  • findHasAndBelongsToMany() public
    Find the hasAndBelongsToMany relations and add them to associations list
  • findHasOneAndMany() public
    Find the hasOne and hasMany relations and add them to associations list
  • findPrimaryKey() public
    Finds a primary Key in a list of fields.
  • getAllTables() public

    Get an Array of all the tables in the supplied connection will halt the script if no tables are found.

  • getName() public
    Forces the user to specify the model he wants to bake, and returns the selected model name.
  • getOptionParser() public
    Gets the option parser instance and configures it.
  • getTable() public
    Interact with the user to determine the table name of a particular model
  • inOptions() public
    Generate a key value list of options and a prompt.
  • initValidations() public
    Populate the _validations array
  • initialize() public
    Override initialize
  • listAll() public
    outputs the a list of possible models or controllers from database

Method Detail

_generatePossibleKeys() protected ¶

_generatePossibleKeys( )

Finds all possible keys to use on custom associations.

Returns
array
Array of tables and possible keys

_getModelObject() protected ¶

_getModelObject( string $className , string $table = null )

Get a model object for a class name.

Parameters
string $className
Name of class you want model to be.
string $table optional null
Table name
Returns
Model
Model instance

_interactive() protected ¶

_interactive( )

Handles interactive baking

Returns
boolean

_printAssociation() protected ¶

_printAssociation( string $modelName , string $type , string $associations )

Print out all the associations of a particular type

Parameters
string $modelName
Name of the model relations belong to.
string $type
Name of association you want to see. i.e. 'belongsTo'
string $associations
Collection of associations.

all() public ¶

all( )

Bake all models at once.

bake() public ¶

bake( string|object $name , array|boolean $data = array() )

Assembles and writes a Model file.

Parameters
string|object $name
Model name or object
array|boolean $data optional array()
if array and $name is not an object assume bake data, otherwise boolean.
Returns
string

bakeFixture() public ¶

bakeFixture( string $className , string $useTable = null )

Interact with FixtureTask to automatically bake fixtures when baking models.

Parameters
string $className
Name of class to bake fixture for
string $useTable optional null
Optional table name for fixture to use.
See
FixtureTask::bake

bakeTest() public ¶

bakeTest( string $className )

Assembles and writes a unit test file

Parameters
string $className
Model class name
Returns
string

confirmAssociations() public ¶

confirmAssociations( Model $model , array $associations )

Interact with the user and confirm associations.

Parameters
Model $model
Temporary Model instance.
array $associations
Array of associations to be confirmed.
Returns
array
Array of confirmed associations

doActsAs() public ¶

doActsAs( Model $model )

Handles behaviors

Parameters
Model $model
The model object.
Returns
array
Behaviors

doAssociations() public ¶

doAssociations( Model $model )

Handles associations

Parameters
Model $model
The model object
Returns
array
Associations

doMoreAssociations() public ¶

doMoreAssociations( Model $model , array $associations )

Interact with the user and generate additional non-conventional associations

Parameters
Model $model
Temporary model instance
array $associations
Array of associations.
Returns
array
Array of associations.

doValidation() public ¶

doValidation( Model $model )

Handles Generation and user interaction for creating validation.

Parameters
Model $model
Model to have validations generated for.
Returns
array
validate Array of user selected validations.

execute() public ¶

execute( )

Execution method always used for tasks

Overrides
BakeTask::execute()

fieldValidation() public ¶

fieldValidation( string $fieldName , array $metaData , string $primaryKey = 'id' )

Does individual field validation handling.

Parameters
string $fieldName
Name of field to be validated.
array $metaData
metadata for field
string $primaryKey optional 'id'
The primary key field.
Returns
array
Array of validation for the field.

findBelongsTo() public ¶

findBelongsTo( Model $model , array $associations )

Find belongsTo relations and add them to the associations list.

Parameters
Model $model
Model instance of model being generated.
array $associations
Array of in progress associations
Returns
array
Associations with belongsTo added in.

findDisplayField() public ¶

findDisplayField( array $fields )

interact with the user to find the displayField value for a model.

Parameters
array $fields
Array of fields to look for and choose as a displayField
Returns
mixed
Name of field to use for displayField or false if the user declines to choose

findHasAndBelongsToMany() public ¶

findHasAndBelongsToMany( Model $model , array $associations )

Find the hasAndBelongsToMany relations and add them to associations list

Parameters
Model $model
Model instance being generated
array $associations
Array of in-progress associations
Returns
array
Associations with hasAndBelongsToMany added in.

findHasOneAndMany() public ¶

findHasOneAndMany( Model $model , array $associations )

Find the hasOne and hasMany relations and add them to associations list

Parameters
Model $model
Model instance being generated
array $associations
Array of in progress associations
Returns
array
Associations with hasOne and hasMany added in.

findPrimaryKey() public ¶

findPrimaryKey( array $fields )

Finds a primary Key in a list of fields.

Parameters
array $fields
Array of fields that might have a primary key.
Returns
string
Name of field that is a primary key.

getAllTables() public ¶

getAllTables( string $useDbConfig = null )

Get an Array of all the tables in the supplied connection will halt the script if no tables are found.

Parameters
string $useDbConfig optional null
Connection name to scan.
Returns
array
Array of tables in the database.

getName() public ¶

getName( string $useDbConfig = null )

Forces the user to specify the model he wants to bake, and returns the selected model name.

Parameters
string $useDbConfig optional null
Database config name
Returns
string
The model name

getOptionParser() public ¶

getOptionParser( )

Gets the option parser instance and configures it.

Returns
ConsoleOptionParser

getTable() public ¶

getTable( string $modelName , string $useDbConfig = null )

Interact with the user to determine the table name of a particular model

Parameters
string $modelName
Name of the model you want a table for.
string $useDbConfig optional null
Name of the database config you want to get tables from.
Returns
string
Table name

inOptions() public ¶

inOptions( array $options , string $prompt = null , integer $default = null )

Generate a key value list of options and a prompt.

Parameters
array $options
Array of options to use for the selections. indexes must start at 0
string $prompt optional null
Prompt to use for options list.
integer $default optional null
The default option for the given prompt.
Returns
integer
Result of user choice.

initValidations() public ¶

initValidations( )

Populate the _validations array

initialize() public ¶

initialize( )

Override initialize

listAll() public ¶

listAll( string $useDbConfig = null )

outputs the a list of possible models or controllers from database

Parameters
string $useDbConfig optional null
Database configuration name
Returns
array

Methods inherited from BakeTask

getPath() public ¶

getPath( )

Gets the path for output. Checks the plugin property and returns the correct path.

Returns
string
Path to output.

startup() public ¶

startup( )

Disable caching and enable debug for baking. This forces the most current database schema to be used.

Properties detail

$_modelNames ¶

protected array

Holds the model names

array()

$_tables ¶

protected array

Holds tables found on connection.

array()

$_validations ¶

protected array

Holds validation method map.

array()

$path ¶

public string

path to Model directory

null

$skipTables ¶

public array

Tables to skip when running all()

array('i18n')

$tasks ¶

public array

tasks

array('DbConfig', 'Fixture', 'Test', 'Template')
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs