2017-11-16 16:39:28 1730次浏览 1条回答 0 悬赏 50 金钱

文件结构如下:
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;
    }
补充于 2017-11-22 15:56

已经解决了。是因为命名空间写错了!

最佳答案

    没有找到数据。
您需要登录后才可以回答。登录 | 立即注册
灰太狼
副总裁

灰太狼

注册时间:2016-11-19
最后登录:2023-07-14
在线时长:76小时17分
  • 粉丝28
  • 金钱3290
  • 威望150
  • 积分5550

热门问题