use 跨应用插件 我怎么拿不到request->plugin 数据,怎么才能实现拿到?

kspade

我自己建立了一个应用插件:took,我想在\app\api\controller\index.php 中拿到took的数据

应用插件Config.php代码:

<?php
namespace plugin\took\app\controller;
use support\Request;
class Config{ 
    protected $plugin = null;
    public function __construct(){ 
        $this->request = Request(); 
        $this->plugin = $this->request->plugin;  //获取当前插件名称
        $this->bot = $this->request->get("bot","null"); //这里是获取的get参数
        if($this->bot == 'null'){
            return "获取get参数bot 失败"; 
        }
    }

    protected function send($msg){  
        return $this->plugin; 
    }
}

应用插件base.php 代码 继承Config.php

<?php
namespace plugin\took\app\controller;

use support\Request;
use support\Response;

class Base extends Config{ 

    public function plugin(){   
        return $this->plugin;
    }

}

重点来了 我这时候想在 其它应用插件里面或者队列,定时任务等文件里面调用base.php 的 public function plugin() 方法

示例代码:


$Base  =  new \plugin\took\app\controller\Base;
$plugin = $Base->plugin();  

这时候根本拿不到 plugin 名,还有什么其它办法拿到 plugin 名吗?
以及如何在 $Base = new \plugin\took\app\controller\Base; 时 给到config中:$this->bot = $this->request->get("bot","null"); 怎么给传这个bot 参数过去?

265 2 0
2个回答

kspade

我如果用:域名/app/took/Base/plugin?bot=ssssssss
这样就可以获取到plugin 和 bot 参数

  • 暂无评论
walkor

按照你的需求,Config的构造函数里直接写死 $this->plugin = 'took'; 就好了

🔝