PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 15, 2022

[FIXED] How to add a class to a Yii form label?

 February 15, 2022     forms, label, yii     No comments   

Issue

To generate the following markup:

<label class="foo">Bar</label>

The PHP will look something like:

<?php echo $form->label($model,'username'); ?>

Seems like it should be part of the htmlOptions parameter to label(), but I couldn't really figure it out.

From Yii's doc:

public string label(CModel $model, string $attribute, array $htmlOptions=array ( ))

Ref:

http://www.yiiframework.com/doc/api/1.1/CActiveForm#label-detail


Solution

As the doc says, $htmlOptions is an array of additional HTML attributes. The keys are the attribute, while the values are the attribute values, so to add a class attribute to the label:

<?php echo $form->label( $model,'username', array('class'=>'className') ); ?>


Answered By - ernie
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing