首页 > Typecho_Widge类的参数问题

Typecho_Widge类的参数问题

我在用typecho做一个微信相关的功能,从服务端的log看到php的报错:

PHP Warning:  Missing argument 1 for Widget_Abstract::__construct(), called in /var/www/typecho.ifme.in/public/usr/plugins/Wechat/Action.php on line 27 and defined in /var/www/typecho.ifme.in/public/var/Widget/Abstract.php on line 62

PHP Warning:  Missing argument 2 for Widget_Abstract::__construct(), called in /var/www/typecho.ifme.in/public/usr/plugins/Wechat/Action.php on line 27 and defined in /var/www/typecho.ifme.in/public/var/Widget/Abstract.php on line 62
...

Widget_Abstract 类构造函数里的前两个参数是 $request 和 $response,通过浏览器访问时,不会产生这个报错,只在接收微信消息时候会出现。
大概看了源码,理解不是很深刻,哪位知道如何处理这个问题?先谢谢了。

Plugin.php 文件,激活插件时只添加了一个路由

    public static function activate()
    {
        Helper::addAction('wechat-service', 'Wechat_Action');
        return _t('微信助手启用成功');
    }

目前报错的Action.php文件(临时还原的),响应微信,自动回复

<?php

class Wechat_Action extends Typecho_Widget implements Widget_Interface_Do
{

    private $db;
    private $config;
    private $wxServer;
    private $wxUser;

    public function __construct($request, $response, $params = NULL)
    {
        parent::__construct($request, $response, $params);
        $this->db = Typecho_Db::get();
        $this->config = parent::widget('Widget_Options')->plugin('Wechat');
        $this->wxServer = new Wechat_Helper_Server($this->config->app_token);
    }

    public function action() {
        $this->init();
    }

    public function init() {
        $info = $this->wxServer->getMessage();

        _log(json_encode($info));

        $this->wxUser = $this->initUser($info);

        if ($info['type'] == 'event') {
            if ($info['event'] == 'subscribe') {
                $this->doSubscribe();
                exit;
            }
            if ($info['event'] == 'unsubscribe') {
                $this->doUnSubscribe();
                exit;
            }
        }

        $query = $this->db->select('cid')
                ->from('table.contents')
                ->where('slug = ?' , 'biubiubiu');

        $target = $this->db->fetchRow($query);

        $this->comment_insert(array(
            'cid' => $target['cid'],
            'author' => $this->wxUser['name'],
            'authorId' => $this->wxUser['uid'],
            'text' => $info['content']
        ));

        $message = $this->config->auto_reply;
        if ($message) echo $this->wxServer->getXml4Txt($message);
    }

    function doSubscribe() {
        $message = $this->config->sub_reply;
        if ($message) echo $this->wxServer->getXml4Txt($message);
    }

    function doUnSubscribe() {
        ......
    }
    function comment_insert() {
        ......
    }
    function $this->initUser($info) {
        ......
    }

}

现在取消了Action.php里对Widget_Abstract的继承,又添加public function execute(){}方法,虽然Warning没了,不过系统很多Widget应该是不能用了


贴你usr/plugins/Wechat/Action.php出问题的行出来看看?估计是你调用的方式不对。
获取去这里找找,看能不能解决你的问题 http://www.typechodev.com/index.php/archives/22/


Action 中的这是什么方法?

phpfunction $this->initUser($info) {
    ......
}
【热门文章】
【热门文章】