Some of the most commonly learned things about yii in PHP

Source: Internet
Author: User
Some of the most commonly used knowledge of yii in PHP

validation length added in the Rules () method
Array (' username ', ' length ', ' min ' =>3, ' Max ' =>12),
where length is found in the following class table, Min and Max class file corresponding to length: Cstringvalidator inside .
These class files are in:.. Under the/frameworks/validators folder
————————————————————————————
the Captcha:ccaptchavalidator alias ensures that the value of the attribute is equal to the verification code displayed by the CAPTCHA.
the alias of the. Compare:ccomparevalidator ensures that the value of the attribute equals another attribute or constant.
the Email:cemailvalidator alias ensures that the value of the attribute is a valid e-mail address.
the alias for the Default:cdefaultvaluevalidator, which assigns a default value to the attribute.
the alias of the. File:cfilevalidator ensures that the feature contains the name of an uploaded file.
? Filter:cfiltervalidator aliases, using a filter to transform the form of an attribute.
the alias of the In:crangevalidator ensures that the feature appears in the list of values for a subscription.
the alias of the Length:cstringvalidator ensures that the length of the feature is within the specified range.
the alias of the Match:cregularexpressionvalidator ensures that the attribute matches a regular expression.
the alias of the Numerical:cnumbervalidator ensures that the feature is a valid number.
the alias of the. Required:crequiredvalidator ensures that the attribute is not empty.
the alias of the. Type:ctypevalidator ensures that the attribute is of the specified data type.
the alias of the. Unique:cuniquevalidator ensures that the attribute is unique in the Data table field.
the alias of the Url:curlvalidator ensures that the feature is a valid path.
————————————————————————————
below we list examples of using predefined validators:
//Username not empty
Array (' username ', ' required '),
//username must be greater than 3 less than 12 bytes
Array (' username ', ' length ', ' min ' =>3, ' Max ' =>12),
//In the registration scenario, password must be the same as Password2
Array (' password ', ' compare ', ' compareattribute ' = ' password2′ ', ' on ' = ' register '),
//In the login scenario, the password must be verified

Array (' Password ', ' Authenticate ', ' on ' = ' login '),

?

1 .....

?

Share to:0

Yii Filter Bad Code

$purifier =new chtmlpurifier; $purifier->options=array ("HTML. Allowed "=" div "); $content = $purifier->purify ($content);


Or

 
  Beginwidget (' Chtmlpurifier ');? >...display user-entered content
 
   here ... Endwidget ();?>

?

?

2 .....

?

Share to:0

How does yii prevent duplicate submissions?

After submission

Ccontroler->refresh ();

?

?

3 .....

?

Yii How to get the URL of the previous page to return

Yii::app ()->request->urlreferrer;

?

?

?

4 .....

?

How Yii can make form validation hints in Chinese

Add the main.php app configuration plus language=> ' ZH_CN ', the system default prompt is Chinese, to customize the message like upstairs to say the definition of messages

?

?

?

5 .....

?

Open source PHP Framework Yii: Multi-database operations

In most cases, we will use the same type of database, just to relieve the pressure into master-slave or distributed form.

Statement

?

You can declare other database connections in the app config:

 
  Array (        ' db ' =>....//primary link         ' db1 ' =>...//from connection 1        ' DB2 ' =>...//from Connection 2    )    ...

Operation

In the code, two slave connections can be obtained through Yii::app ()->DB1 and Yii::app ()->db2.

Advanced operations

More advanced (automatic) master-slave database functionality will be implemented in 1.1.

?

?

For more details, go to: http://www.thinksaas.cn/group/show/id-283

  • 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.