ControllerTask Class Info:
- Class Declaration:
class ControllerTask extends BakeTask
- File name:
- Cake/Console/Command/Task/ControllerTask.php
- Description:
Task class for creating and updating controller files.
- Class Inheritance
- Package
- Cake.Console.Command.Task
Properties:
-
args array
Contains arguments parsed from the command line.
-
command string
The command (method/task) that is being run.
-
connection string
The db connection being used for baking
-
interactive boolean
Flag for interactive mode
-
name string
The name of the shell in camelized.
-
OptionParser ConsoleOptionParser
An instance of ConsoleOptionParser that has been configured for this class.
-
params array
Contains command switches parsed from the command line.
-
path array
path to Controller directory
-
plugin string
Name of plugin
-
stderr ConsoleOutput
stderr object.
-
stdin ConsoleInput
stdin object
-
stdout ConsoleOutput
stdout object.
-
_taskMap string
Normalized map of tasks.
-
taskNames array
Contains the loaded tasks
-
tasks array
Tasks to be loaded by this Task
-
Tasks TaskCollection
Task Collection for the command, used to create Tasks.
-
uses array
Contains models to load and instantiate
Method Summary:
- all( )
- _askAboutMethods( )
- bake( $controllerName, $actions = '', $helpers = NULL, $components = NULL )
- bakeActions( $controllerName, $admin = NULL, $wannaUseSession = true )
- bakeTest( $className )
- _checkUnitTest( )
- clear( )
- confirmController( $controllerName, $useDynamicScaffold, $helpers, $components )
- __construct( $stdout = NULL, $stderr = NULL, $stdin = NULL )
- _controllerName( $name )
- _controllerPath( $name )
- createFile( $path, $contents )
- dispatchMethod( $method, $params = array ( ) )
- dispatchShell( )
- _displayHelp( $command )
- doComponents( )
- doHelpers( )
- _doPropertyChoices( $prompt, $example )
- err( $message = NULL, $newlines = 1 )
- error( $title, $message = NULL )
- execute( )
- __get( $name )
- _getInput( $prompt, $options, $default )
- getName( $useDbConfig = NULL )
- getOptionParser( )
- getPath( )
- hasMethod( $name )
- hasTask( $task )
- hr( $newlines = 0, $width = 63 )
- in( $prompt, $options = NULL, $default = NULL )
- initialize( )
- _interactive( )
- listAll( $useDbConfig = NULL )
- _loadModels( )
- loadTasks( )
- log( $msg, $type = 2 )
- _mergeVars( $properties, $class, $normalize = true )
- _modelKey( $name )
- _modelName( $name )
- _modelNameFromKey( $key )
- nl( $multiplier = 1 )
- out( $message = NULL, $newlines = 1, $level = 1 )
- _pluginPath( $pluginName )
- _pluralHumanName( $name )
- _pluralName( $name )
- requestAction( $url, $extra = array ( ) )
- runCommand( $command, $argv )
- _set( $properties = array ( ) )
- shortPath( $file )
- _singularHumanName( $name )
- _singularName( $name )
- startup( )
- _stop( $status = 0 )
- toString( )
- _welcome( )
- wrapText( $text, $options = array ( ) )
all
topBake All the controllers at once. Will only bake controllers for models that exist.
- Method defined in:
- Cake/Console/Command/Task/ControllerTask.php on line 103
- Return
void
_askAboutMethods
topInteract with the user and ask about which methods (admin or regular they want to bake)
- Method defined in:
- Cake/Console/Command/Task/ControllerTask.php on line 252
- Return
array Array containing (bakeRegular, bakeAdmin) answers
bake
topAssembles and writes a Controller file
- Parameters:
-
-
string $controllerName required
Controller name already pluralized and correctly cased.
-
string $actions optional ''
Actions to add, or set the whole controller to use $scaffold (set $actions to 'scaffold')
-
array $helpers optional NULL
Helpers to use in controller
-
array $components optional NULL
Components to use in controller
-
- Method defined in:
- Cake/Console/Command/Task/ControllerTask.php on line 311
- Return
string Baked controller
bakeActions
topBake scaffold actions
- Parameters:
-
-
string $controllerName required
Controller name
-
string $admin optional NULL
Admin route to use
-
boolean $wannaUseSession optional true
Set to true to use sessions, false otherwise
-
- Method defined in:
- Cake/Console/Command/Task/ControllerTask.php on line 272
- Return
string Baked actions
bakeTest
topAssembles and writes a unit test file
- Parameters:
-
-
string $className required
Controller class name
-
- Method defined in:
- Cake/Console/Command/Task/ControllerTask.php on line 337
- Return
string Baked test
_checkUnitTest
topAction to create a Unit Test
- Method defined in:
- Cake/Console/Shell.php on line 682
- Return
boolean Success
clear
topClear the console
- Method defined in:
- Cake/Console/Shell.php on line 627
- Return
void
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::clear
confirmController
topConfirm a to be baked controller with the user
- Parameters:
-
-
string $controllerName required
-
string $useDynamicScaffold required
-
array $helpers required
-
array $components required
-
- Method defined in:
- Cake/Console/Command/Task/ControllerTask.php on line 214
- Return
void
__construct
topConstructs this Shell instance.
- Parameters:
-
-
ConsoleOutput $stdout optional NULL
A ConsoleOutput object for stdout.
-
ConsoleOutput $stderr optional NULL
A ConsoleOutput object for stderr.
-
ConsoleInput $stdin optional NULL
A ConsoleInput object for stdin.
-
- Method defined in:
- Cake/Console/Shell.php on line 156
_controllerName
topCreates the proper controller plural name for the specified controller class name
- Parameters:
-
-
string $name required
Controller class name
-
- Method defined in:
- Cake/Console/Shell.php on line 729
- Return
string Controller plural name
_controllerPath
topCreates the proper controller path for the specified controller class name
- Parameters:
-
-
string $name required
Controller class name
-
- Method defined in:
- Cake/Console/Shell.php on line 719
- Return
string Path to controller
createFile
topCreates a file at given path
- Parameters:
-
-
string $path required
Where to put the file.
-
string $contents required
Content to put in the file.
-
- Method defined in:
- Cake/Console/Shell.php on line 645
- Return
boolean Success
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::createFile
dispatchMethod
topCalls a method on this object with the given parameters. Provides an OO wrapper
for call_user_func_array
- Parameters:
-
-
string $method required
Name of the method to call
-
array $params optional array ( )
Parameter list to use when calling $method
-
- Method defined in:
- Cake/Core/Object.php on line 110
- Return
mixed Returns the result of the method call
dispatchShell
topDispatch a command to another Shell. Similar to Object::requestAction() but intended for running shells from other shells.
Usage:
With a string command:
`return $this->dispatchShell('schema create DbAcl');`
Avoid using this form if you have string arguments, with spaces in them. The dispatched will be invoked incorrectly. Only use this form for simple command dispatching.
With an array command:
return $this->dispatchShell('schema', 'create', 'i18n', '--dry');
- Method defined in:
- Cake/Console/Shell.php on line 326
- Return
mixed The return of the other shell.
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::dispatchShell
_displayHelp
topDisplay the help in the correct format
- Parameters:
-
-
string $command required
-
- Method defined in:
- Cake/Console/Shell.php on line 401
- Return
void
doComponents
topInteract with the user and get a list of additional components
- Method defined in:
- Cake/Console/Command/Task/ControllerTask.php on line 361
- Return
array Components the user wants to use.
doHelpers
topInteract with the user and get a list of additional helpers
- Method defined in:
- Cake/Console/Command/Task/ControllerTask.php on line 349
- Return
array Helpers that the user wants to use.
_doPropertyChoices
topCommon code for property choice handling.
- Parameters:
-
-
string $prompt required
A yes/no question to precede the list
-
string $example required
A question for a comma separated list, with examples.
-
- Method defined in:
- Cake/Console/Command/Task/ControllerTask.php on line 375
- Return
array Array of values for property.
err
topOutputs a single or multiple error messages to stderr. If no parameters are passed outputs just a newline.
- Parameters:
-
-
mixed $message optional NULL
A string or a an array of strings to output
-
integer $newlines optional 1
Number of newlines to append
-
- Method defined in:
- Cake/Console/Shell.php on line 574
- Return
void
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::err
error
topDisplays a formatted error message and exits the application with status code 1
- Parameters:
-
-
string $title required
Title of the error
-
string $message optional NULL
An optional error message
-
- Method defined in:
- Cake/Console/Shell.php on line 612
- Return
void
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::error
execute
topExecution method always used for tasks
- Method defined in:
- Cake/Console/Command/Task/ControllerTask.php on line 58
- Return
void
__get
topOverload get for lazy building of tasks
- Parameters:
-
-
string $name required
-
- Method defined in:
- Cake/Console/Shell.php on line 431
- Return
Shell Object of Task
_getInput
topPrompts the user for input, and returns it.
- Parameters:
-
-
string $prompt required
Prompt text.
-
mixed $options required
Array or string of options.
-
string $default required
Default input value.
-
- Method defined in:
- Cake/Console/Shell.php on line 489
- Return
Either the default value, or the user-provided input.
getName
topForces the user to specify the controller he wants to bake, and returns the selected controller name.
- Parameters:
-
-
string $useDbConfig optional NULL
Connection name to get a controller name for.
-
- Method defined in:
- Cake/Console/Command/Task/ControllerTask.php on line 417
- Return
string Controller name
getOptionParser
topget the option parser.
- Method defined in:
- Cake/Console/Command/Task/ControllerTask.php on line 447
- Return
void
getPath
topGets the path for output. Checks the plugin property and returns the correct path.
- Method defined in:
- Cake/Console/Command/Task/BakeTask.php on line 67
- Return
string Path to output.
hasMethod
topCheck to see if this shell has a callable method by the given name.
- Parameters:
-
-
string $name required
The method name to check.
-
- Method defined in:
- Cake/Console/Shell.php on line 290
- Return
boolean
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::hasMethod
hasTask
topCheck to see if this shell has a task with the provided name.
- Parameters:
-
-
string $task required
The task name to check.
-
- Method defined in:
- Cake/Console/Shell.php on line 279
- Return
boolean Success
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::hasTask
hr
topOutputs a series of minus characters to the standard output, acts as a visual separator.
- Parameters:
-
-
integer $newlines optional 0
Number of newlines to pre- and append
-
integer $width optional 63
Width of the line, defaults to 63
-
- Method defined in:
- Cake/Console/Shell.php on line 597
- Return
void
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::hr
in
topPrompts the user for input, and returns it.
- Parameters:
-
-
string $prompt required
Prompt text.
-
mixed $options optional NULL
Array or string of options.
-
string $default optional NULL
Default input value.
-
- Method defined in:
- Cake/Console/Shell.php on line 452
- Return
mixed Either the default value, or the user-provided input.
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::in
initialize
topOverride initialize
- Method defined in:
- Cake/Console/Command/Task/ControllerTask.php on line 49
- Return
void
_interactive
toplistAll
topOutputs and gets the list of possible controllers from database
- Parameters:
-
-
string $useDbConfig optional NULL
Database configuration name
-
- Method defined in:
- Cake/Console/Command/Task/ControllerTask.php on line 392
- Return
array Set of controllers
_loadModels
topIf $uses = true Loads AppModel file and constructs AppModel class makes $this->AppModel available to subclasses If public $uses is an array of models will load those models
- Method defined in:
- Cake/Console/Shell.php on line 232
- Return
boolean
loadTasks
topLoads tasks defined in public $tasks
- Method defined in:
- Cake/Console/Shell.php on line 261
- Return
boolean
log
topConvenience method to write a message to CakeLog. See CakeLog::write() for more information on writing to logs.
- Parameters:
-
-
string $msg required
Log message
-
integer $type optional 2
Error type constant. Defined in app/Config/core.php.
-
- Method defined in:
- Cake/Core/Object.php on line 149
- Return
boolean Success of log write
_mergeVars
topMerges this objects $property with the property in $class' definition. This classes value for the property will be merged on top of $class'
This provides some of the DRY magic CakePHP provides. If you want to shut it off, redefine this method as an empty function.
- Parameters:
-
-
array $properties required
The name of the properties to merge.
-
string $class required
The class to merge the property with.
-
boolean $normalize optional true
Set to true to run the properties through Set::normalize() before merging.
-
- Method defined in:
- Cake/Core/Object.php on line 187
- Return
void
_modelKey
topCreates the proper underscored model key for associations
- Parameters:
-
-
string $name required
Model class name
-
- Method defined in:
- Cake/Console/Shell.php on line 749
- Return
string Singular model key
_modelName
topCreates the proper model camelized name (singularized) for the specified name
- Parameters:
-
-
string $name required
Name
-
- Method defined in:
- Cake/Console/Shell.php on line 739
- Return
string Camelized and singularized model name
_modelNameFromKey
topCreates the proper model name from a foreign key
- Parameters:
-
-
string $key required
Foreign key
-
- Method defined in:
- Cake/Console/Shell.php on line 759
- Return
string Model name
nl
topReturns a single or multiple linefeeds sequences.
- Parameters:
-
-
integer $multiplier optional 1
Number of times the linefeed sequence should be repeated
-
- Method defined in:
- Cake/Console/Shell.php on line 585
- Return
string
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::nl
out
topOutputs a single or multiple messages to stdout. If no parameters are passed outputs just a newline.
Output levels
There are 3 built-in output level. Shell::QUIET, Shell::NORMAL, Shell::VERBOSE.
The verbose and quiet output levels, map to the verbose and quiet output switches
present in most shells. Using Shell::QUIET for a message means it will always display.
While using Shell::VERBOSE means it will only display when verbose output is toggled.
- Parameters:
-
-
mixed $message optional NULL
A string or a an array of strings to output
-
integer $newlines optional 1
Number of newlines to append
-
integer $level optional 1
The message's output level, see above.
-
- Method defined in:
- Cake/Console/Shell.php on line 551
- Return
integer|boolean Returns the number of bytes returned from writing to stdout.
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::out
_pluginPath
topFind the correct path for a plugin. Scans $pluginPaths for the plugin you want.
- Parameters:
-
-
string $pluginName required
Name of the plugin you want ie. DebugKit
-
- Method defined in:
- Cake/Console/Shell.php on line 809
- Return
string $path path to the correct plugin.
_pluralHumanName
topCreates the plural human name used in views
- Parameters:
-
-
string $name required
Controller name
-
- Method defined in:
- Cake/Console/Shell.php on line 799
- Return
string Plural human name
_pluralName
topCreates the plural name for views
- Parameters:
-
-
string $name required
Name to use
-
- Method defined in:
- Cake/Console/Shell.php on line 779
- Return
string Plural name for views
requestAction
topCalls a controller's method from any location. Can be used to connect controllers together or tie plugins into a main application. requestAction can be used to return rendered views or fetch the return value from controller actions.
Under the hood this method uses Router::reverse() to convert the $url parameter into a string URL. You should use URL formats that are compatible with Router::reverse()
Passing POST and GET data
POST and GET data can be simulated in requestAction. Use $extra['url'] for
GET data. The $extra['data'] parameter allows POST data simulation.
- Parameters:
-
-
mixed $url required
String or array-based url. Unlike other url arrays in CakePHP, this url will not automatically handle passed and named arguments in the $url parameter.
-
array $extra optional array ( )
if array includes the key "return" it sets the AutoRender to true. Can also be used to submit GET/POST data, and named/passed arguments.
-
- Method defined in:
- Cake/Core/Object.php on line 66
- Return
mixed Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.
runCommand
topRuns the Shell with the provided argv.
Delegates calls to Tasks and resolves methods inside the class. Commands are looked up with the following order:
- Method on the shell.
- Matching task name.
main()method.
If a shell implements a main() method, all missing method calls will be sent to
main() with the original method name in the argv.
- Parameters:
-
-
string $command required
The command name to run on this shell. If this argument is empty, and the shell has a
main()method, that will be called instead. -
array $argv required
Array of arguments to run the shell with. This array should be missing the shell name.
-
- Method defined in:
- Cake/Console/Shell.php on line 355
_set
topAllows setting of multiple properties of the object in a single line of code. Will only set properties that are part of a class declaration.
- Parameters:
-
-
array $properties optional array ( )
An associative array containing properties and corresponding values.
-
- Method defined in:
- Cake/Core/Object.php on line 164
- Return
void
shortPath
topMakes absolute file path easier to read
- Parameters:
-
-
string $file required
Absolute file path
-
- Method defined in:
- Cake/Console/Shell.php on line 707
- Return
string short path
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::shortPath
_singularHumanName
topCreates the singular human name used in views
- Parameters:
-
-
string $name required
Controller name
-
- Method defined in:
- Cake/Console/Shell.php on line 789
- Return
string Singular human name
_singularName
topcreates the singular name for use in views.
- Parameters:
-
-
string $name required
-
- Method defined in:
- Cake/Console/Shell.php on line 769
- Return
string $name
startup
topDisable caching and enable debug for baking. This forces the most current database schema to be used.
- Method defined in:
- Cake/Console/Command/Task/BakeTask.php on line 55
- Return
void
_stop
topStop execution of the current script. Wraps exit() making testing easier.
- Parameters:
-
-
integer|string $status optional 0
see http://php.net/exit for values
-
- Method defined in:
- Cake/Core/Object.php on line 137
- Return
void
toString
topObject-to-string conversion. Each class can override this method as necessary.
- Method defined in:
- Cake/Core/Object.php on line 41
- Return
string The name of this class
_welcome
topwrapText
topWrap a block of text. Allows you to set the width, and indenting on a block of text.
Options
widthThe width to wrap to. Defaults to 72wordWrapOnly wrap on words breaks (spaces) Defaults to true.indentIndent the text with the string provided. Defaults to null.
- Parameters:
-
-
string $text required
Text the text to format.
-
mixed $options optional array ( )
Array of options to use, or an integer to wrap the text to.
-
- Method defined in:
- Cake/Console/Shell.php on line 530
- Return
string Wrapped / indented text
- See
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::wrapText
