PHP命名空间带来的干扰

有时候,不想受命名空间约束,就可以整一个全局类。

protected function sendDayuSms($tel,$code,$template_type,$product = "【易商城】") {
        if ($template_type == 1) {
            $signname = C('dayu_template_register.signname');
            $templatecode = C('dayu_template_register.templatecode');
        }

        if ($template_type == 2) {
            $signname = C('dayu_template_alteration.signname');
            $templatecode = C('dayu_template_alteration.templatecode');
        }

        if ($template_type == 3) {
            $signname = C('dayu_template_identity.signname');
            $templatecode = C('dayu_template_identity.templatecode');
        }
        
        require APP_PATH . 'Lib/Taobaosdk/TopSdk.php';
        $c = new \TopClient;   // 全局类
        $c->appkey = C('dayu_appkey');
        $c->secretKey = C('dayu_secretKey');
        $req = new \AlibabaAliqinFcSmsNumSendRequest;
        $req->setSmsType("normal");
        $req->setSmsFreeSignName("{$signname}");
        $req->setSmsParam('{"code":"'. $code .'","product":"'. $product .'"}');
        $req->setRecNum("{$tel}");
        $req->setSmsTemplateCode("{$templatecode}");
        $resp = $c->execute($req);
        return $resp;
}

这里新建类的时候,加一个\就可以实现了。
如果不加斜杠,由于头部有命名空间。

<?php
/**
 * 基类
 * 
 */
namespace Home\Controller;
use Think\Controller;
class BaseController extends Controller {

默认就会加上命名空间,然后系统就找不到你想要的类了。



本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/5460676.html,如需转载请自行联系原作者


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值