cakephp-2.0 > FormHelper :: label()
A AbstractTransport AclBehavior AclComponent AclInterface AclNode AclShell Aco AcoAction ActionsAuthorize ApcEngine ApiShell App AppController AppController AppHelper AppHelper AppModel AppModel AppShell Aro AuthComponent B BadRequestException BakeShell BakeTask BaseAuthenticate BaseAuthorize BasicAuthenticate BasicAuthentication BehaviorCollection C Cache CacheEngine CacheException CacheHelper CacheSession CakeEmail CakeErrorController CakeException CakeLog CakeLogException CakeLogInterface CakePlugin CakeRequest CakeResponse CakeRoute CakeSchema CakeSession CakeSessionException CakeSessionHandlerInterface CakeSocket ClassRegistry CommandListShell Component ComponentCollection ConfigReaderInterface Configure ConfigureException ConnectionManager ConsoleErrorHandler ConsoleException ConsoleInput ConsoleInputArgument ConsoleInputOption ConsoleInputSubcommand ConsoleOptionParser ConsoleOutput ConsoleShell ContainableBehavior Controller ControllerAuthorize ControllerTask CookieComponent CrudAuthorize D DatabaseSession DataSource DbAcl DbAclSchema DbConfigTask DboSource Debugger DebugTransport DigestAuthenticate DigestAuthentication Dispatcher E EmailComponent ErrorHandler ExceptionRenderer ExtractTask F File FileEngine FileLog FixtureTask Folder ForbiddenException FormAuthenticate FormHelper H Helper HelperCollection HelpFormatter HtmlHelper HttpException HttpResponse HttpSocket I I18n I18nModel i18nSchema I18nShell Inflector IniReader InternalErrorException J JqueryEngineHelper JsBaseEngineHelper JsHelper L L10n M MailTransport MediaView MemcacheEngine MethodNotAllowedException MissingActionException MissingBehaviorException MissingComponentException MissingConnectionException MissingControllerException MissingDatabaseException MissingDatasourceConfigException MissingDatasourceException MissingHelperException MissingLayoutException MissingModelException MissingPluginException MissingShellException MissingShellMethodException MissingTableException MissingTaskException MissingTestLoaderException MissingViewException Model ModelBehavior ModelTask MootoolsEngineHelper Multibyte Mysql N NotFoundException NumberHelper O Object ObjectCollection P PagesController PagesController PaginatorComponent PaginatorHelper Permission PhpReader PluginShortRoute PluginTask Postgres PrivateActionException ProjectTask PrototypeEngineHelper R RedirectRoute RequestHandlerComponent Router RouterException RssHelper S Sanitize Scaffold ScaffoldView SchemaShell Security SecurityComponent SessionComponent SessionHelper SessionsSchema Set Shell ShellDispatcher SmtpTransport SocketException Sqlite Sqlserver String T TaskCollection TemplateTask TestsuiteShell TestTask TextHelper ThemeView TimeHelper TranslateBehavior TreeBehavior U UnauthorizedException UpgradeShell V Validation View ViewTask W WincacheEngine X XcacheEngine Xml XmlException

label

line:786 at /lib/Cake/View/Helper/FormHelper.php
Returns a formatted LABEL element for HTML FORMs. Will automatically generate a for attribute if one is not provided.

Method

(string) public label ($fieldName = null, $text = null, $options = array())

Parameters

ParameterTypeCommentDefault
$fieldName string optional This should be "Modelname.fieldname" null
$text string optional Text that will appear in the label field. If $text is left undefined the text will be inflected from the fieldName. null
$options mixed optional An array of HTML attributes, or a string, to be used as a class name. array()

Return

string

Comment

Returns a formatted LABEL element for HTML FORMs. Will automatically generate
a for attribute if one is not provided.

### Options

- `for` - Set the for attribute, if its not defined the for attribute
will be generated from the $fieldName parameter using
FormHelper::domId().

Examples:

The text and for attribute are generated off of the fieldname

{{{
echo $this->Form->label('Post.published');
<label for="PostPublished">Published</label>
}}}

Custom text:

{{{
echo $this->Form->label('Post.published', 'Publish');
<label for="PostPublished">Publish</label>
}}}

Custom class name:

{{{
echo $this->Form->label('Post.published', 'Publish', 'required');
<label for="PostPublished" class="required">Publish</label>
}}}

Custom attributes:

{{{
echo $this->Form->label('Post.published', 'Publish', array(
'for' => 'post-publish'
));
<label for="post-publish">Publish</label>
}}}

@param string $fieldName This should be "Modelname.fieldname"
@param string $text Text that will appear in the label field. If
$text is left undefined the text will be inflected from the
fieldName.
@param mixed $options An array of HTML attributes, or a string, to be used as a class name.
@return string The formatted LABEL element
@link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::label