谁一开始就是大神?

开发组件,扩展Widget时无法调用widget部件[2.0]

文件结构如下:
4BA40968-78E1-488A-AEEF-80FDBC4693A8.png

入口:根目录下的text.php

require_once __DIR__ . '/vendor/autoload.php';
use Hello\SayHello;

echo SayHello::world();

SayHello类如下:


namespace Hello;

use app\TestWidgets\ProgressWidget;

class SayHello
{
    public static function world()
    {
        return  122;
        return  ProgressWidget::widget(['message'=>1232213]);
    }

问题是,world方法直接返回122或任何数字,字符串。都可以在页面渲染出来。
如果改成 return ProgressWidget::widget([‘message’=>1232213]); 就会报500

ProgressWidget.php 如下


/**
 *
 */
namespace app\TestWidgets;

class ProgressWidget extends \yii\base\Widget
{
    public $message;

    public function init()
    {
        parent::init();
        if($this->message === null){
            $this->message = '<div class="color:red;">Hello World</div>';
        }else{
            $this->message = '<div style="color:red;">'.$this->message.'</div>';
        }
    }

    public function run(){

        //        return $this->render('hello');
        return 123;
    }

test.php加上require Yii.php

赞(0) 打赏
未经允许不得转载:菜鸟之家 » 开发组件,扩展Widget时无法调用widget部件[2.0]

评论 抢沙发

登录

找回密码

注册