项目中经常会将一些公共的方法或变量放在一个模块中,称之为公共模块。
公共模块直接继承Action类,其他模块都继承公共模块。
那么如何防止公共模块直接被外部访问呢?
例如,定义了一个公共模块 CommonActionclass CommonAction extends Action {<br>
public $uid;<br>
……<br>
}
其他模块:class UserAction extends CommonAction {<br>
function index(){<br>
echo $this->uid; //这里就可以直接使用公共类的变量<br>
}<br>
……<br>
}
但是如果我们在CommonAction 中定义了一个操作时,如果不做处理,访客可以直接通过 /index.php/Common/操作名
而一般公共模块是不想让访客直接访问的。
这时,只要做一个简单的处理就可以。
1.在UserAction.class.php 文件中:<?php <br />
define("INC",1);//定义INC常量<br>
class UserAction extends CommonAction {<br>
……<br>
}<br>
?>
2.在CommonAction.class.php中:<?php <br />
//判断是否有定义INC,没有则直接退出<br>
if(!defined("INC")){<br>
exit('Access Denied');<br>
}<br>
class CommonAction extends Action {<br>
……<br>
}<br>
?>
AD:真正免费,域名+虚机+企业邮箱=0元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.