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

Sunday, January 9, 2022

[FIXED] Yii : How to make a button with an html tag inside the label

 January 09, 2022     php, twitter-bootstrap, yii     No comments   

Issue

I'm trying to use some bootstrap features like the Icon glyphs in the Yii CHtml class, here is my code:

<?php 
   echo CHtml::submitButton('<i class="icon-user"></i> Login', 
       array(
           'class' => 'btn btn-large pull-right'
       )); 
 ?>

But it kinda don't "recognize" the tag and just renders the tag out like the image bellow .enter image description here

does anyone knows how to workaround it (without typing the html tags itself).

Thank you guys.


Solution

CHtml::submitButton produces an <input type="submit"> that cannot accept additional HTML as its content. However, you can do things to taste with CHtml::tag:

echo CHtml::tag('button',
                array('class' => 'btn btn-large pull-right'),
                '<i class="icon-user"></i> Login');

This will produce a <button> tag that can take arbitrary HTML as its content.

Update: As frostyterrier points out in the comments, there's a built-in method CHtml::htmlButton that allows you to do this even more easily:

echo CHtml::htmlButton('<i class="icon-user"></i> Login',
                       array('class' => 'btn btn-large pull-right'));


Answered By - Jon
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

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