Netbeans 中 Yii 2 行为 class 未使用的 use 语句

Unused use statement with Yii 2 behavior class in Netbeans

<?php
namespace app\controllers;

use Yii;
use yii\web\Controller;
use app\models\Category;
use app\components\NewsBehavior;

class ModelTestController extends Controller
{

class app\components\NewsBehavior 存在,但 Netbeans 给出警告:

Unused use statement (on the line: use app\components\NewsBehavior;).

NewsBehavior class 不能直接使用,因为它是行为。

这意味着你定义了它,但没有在当前class中使用它(至少明确地)。

如果您在当前 class 中不需要它,只需删除此声明。

否则,如果您将行为 class 配置为字符串(例如:'class' => 'app\components\NewsBehavior',显然这个声明的 class 不会直接使用,并且在当前形式中 use 是多余的。

然而,还有另一种使用静态 className() 方法传递 class 的方法:

'class' => NewsBehavior::className(),

如果您要使用它,那么 IDE 通知将会消失,因为现在您明确指的是 class。

官方文档: