Php inherited app _ PHP Tutorial

Source: Internet
Author: User
An application inherited by php. So I think of inheritance to solve, previously published a session class, this is much simpler, set the user level through login, $ session-get_status () return value if it is 0, in this case
I thought of inheritance to solve the problem. I have previously published a session class, which is much simpler. I set the user level through login, and the return of $ session-> get_status ()
If the value is 0, it indicates that the current user is not a blogger and therefore does not have the permission to delete or edit an article. If the return value is 1, it indicates that it is the blogger himself. Good
No. Code First

The code is as follows:


Class operationLimit
// Operating limit. When no user login or is not this user
{
/* For limit the user operat post.
* @ Author: xiaoai 8.12 2011
*/
Static $ limitObject;
Public function _ construct (){}
// When call the function but does not exist
Public static function getObject ()
{
If (! (Self: $ limitObject instanceof self ))
Self: $ limitObject = new self;
Return self: $ limitObject;
}
Protected function setLimit (){}
Public function getReadA ($ postName)
{
Return ''. php \ 'class = \ 'readmorelink \ '> readmore ';
}
}
Class operationUnlimit extends operationLimit
// When is this user
{
Public static function getObject ()
{
If (! (Self: $ limitObject instanceof self ))
Self: $ limitObject = new self;
Return self: $ limitObject;
}
Public function getUpdateA ($ name)
{
Return ''. php? Do = update \ 'Id = \ ''. $ name. '\'> update ';
}
Public function getDelectA ($ name)
{
Return '.'); \ 'Id = \ 'delectpost \ '> delect ';
}
}
Class LimitFactory
{
Public static function getLimitObject ($ userStatus)
// $ UserStatus = $ session-> get_status ();
{
Switch ($ userStatus)
{
Case 0:
Return operationLimit: getObject ();
Case 1:
Return operationUnlimit: getObject ();
Default:
Return limit: getObject ();
}
}
}


LimitFactory is a factory class and static class. That is, you do not need to construct an object. Its role is to judge whether the returned operationLimit class or operationUnlimit class instance is based on the passed user permission value.
There are some common operations, such as reading more, the operationUnlimit class inherits this method, and then creates some new methods, such as return deletion and update link methods.
Usage example

The code is as follows:


$ LimitObj = LimitFactory: getLimitObject ($ session-> get_status ());
Echo $ limitObj-> getReadA ('hi ');
Echo $ limitObj-> getDelectA ('hah ');


At the beginning, when I did not write the getObject () static method in the operationUnlimit class, I found that
Return operationUnlimit: getObject ();
The returned result is a superclass object. it is strange that I use self in the getObject (); method to represent the current class. it does not indicate that the superclass object must be returned. When
Class. Later, I checked google and vaguely understood that the compiler bound the getObject method and the superclass at the beginning, so
The call in the subclass still returns the superclass object.

Also, do you think it is difficult to distinguish so many escape characters in the string?
Echo < Read more
Eeeeeee;
This is refreshing.

Pipeline thought of the inheritance to solve, previously published a session class, this is much simpler, through login to set the user level, $ session-get_status () returned value if it is 0, then the table...

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.