//定義是MyController.php
namespace appcomponents;
use yiibaseWidget;
use yiihelpersHtml;
class HelloWidget extends Widget
{
public $message;public function init(){ parent::init(); if ($this->message === null) { $this->message = 'Hello World'; }}public function run(){ return Html::encode($this->message);}
}
//然後調用是在view中
use appcomponentsHelloWidget;
?>
'Good morning']) ?>
//結果報錯找不到組件
Class 'appcomponentsHelloWidget' not found
請問我定義是不是錯了呀?
回複內容:
//定義是MyController.php
namespace appcomponents;
use yiibaseWidget;
use yiihelpersHtml;
class HelloWidget extends Widget
{
public $message;public function init(){ parent::init(); if ($this->message === null) { $this->message = 'Hello World'; }}public function run(){ return Html::encode($this->message);}
}
//然後調用是在view中
use appcomponentsHelloWidget;
?>
'Good morning']) ?>
//結果報錯找不到組件
Class 'appcomponentsHelloWidget' not found
請問我定義是不是錯了呀?
命名空間的問題
很少用app開始的明明空間,一般都是common/components;或者根據模組來,frontend backend