php继承的一个应用
前端之家收集整理的这篇文章主要介绍了
php继承的一个应用,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这样我
想到了继承来解决,前面发表过一个会话类,这下简单多了,通过登录来设置用户的级别,$session->get_status()的返回
值如果是0,则表明当前用户并不是博主,因此并不具有删除,编辑文章的权限。如果是返回值是1,则表明是博主本人。好
了,废话少扯。先上代码
<div class="codetitle"><a style="CURSOR: pointer" data="76057" class="copybut" id="copybut76057" onclick="doCopy('code76057')"> 代码如下:
<div class="codebody" id="code76057">
class operationLimit
// operating limit. When no user login or is not this user
{
/
for limit the user operat at 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 '<a herf=\'
http://foodstory.me/post/'.$postname.
'.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 '<a href=\'
http://foodstory.me/post/'.$name.
'.php?do=update\' id=\''.$name.'\' >update';
}
public function getDelectA($name)
{
return '<a href=\'javascript:delectPOST('.$name
.');\' 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();
}
}
}