Yii method to remove the asterisk in required fields, Yii required fields asterisk _php tutorial

Source: Internet
Author: User
Tags php framework

Yii removes the asterisk from the required fields, and the asterisk in the Yii mandatory fields


This example describes how Yii removes asterisks from required fields. Share to everyone for your reference, as follows:

How do I get rid of the asterisk in the required fields?

First analyze the following code implementation:

Public Function Labelex ($model, $attribute, $htmlOptions =array ()) {  return Chtml::activelabelex ($model, $ attribute, $htmlOptions);} public static function Activelabelex ($model, $attribute, $htmlOptions =array ()) {  $realAttribute = $attribute;  Self::resolvename ($model, $attribute); Strip off square brackets if any  $htmlOptions [' Required ']= $model->isattributerequired ($attribute);  Return Self::activelabel ($model, $realAttribute, $htmlOptions);}

When a property is required, it renders additional CSS class tags. In particular, it calls cmodel::isattributerequired to determine if a property is required. If it is, it adds a CSS class chtml::requiredcss (public static $REQUIREDCSS = ' required ';) to the label, with Chtml::beforerequiredlabel (public static $beforeRequiredLabel = ";) and Chtml::afterrequiredlabel (public static $afterRequiredLabel = ' * ';) to decorate the label.

Public Function isattributerequired ($attribute) {  foreach ($this->getvalidators ($attribute) as $validator)  {    if ($validator instanceof Crequiredvalidator) return true;  }  return false;}

So you have to remove the asterisk or replace it with another view directly redefine Chtml::requiredcss, Chtml::beforerequiredlabel, Chtml::afterrequiredlabel can

Do not display an asterisk

<?php CHtml:: $afterRequiredLabel = ";? ><?php echo $form->labelex ($model, ' email ');?>

It is hoped that this article is helpful to the PHP program design based on YII framework.

Articles you may be interested in:

    • The directory structure, portal files, and routing settings for the Yii introductory tutorial
    • Yii Installation and Hello World
    • YII PHP Framework Practical Introductory Tutorial (detailed)
    • Yii Query Builder Usage Example tutorial
    • Yii uses URL components to beautify the management method
    • The method of Cgridview implementation in Yii for batch deletion
    • Methods of Yii Authority control (three methods)
    • The query method of Yii database
    • Yiiframework Introductory Knowledge Point Summary (graphic tutorial)

http://www.bkjia.com/PHPjc/1085881.html www.bkjia.com true http://www.bkjia.com/PHPjc/1085881.html techarticle Yii removes the asterisk in the required fields, and the asterisk in the mandatory fields of Yii This example describes the method by which Yii removes the asterisk from the required fields. Share to everyone for your reference, as follows: How to remove ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.