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


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
{

app'components'NewsBehavior存在,但 Netbeans 发出警告:

未使用的 use 语句(在行上:use app''components''NewsBehavior;(。

NewsBehavior类不能直接使用,因为它的行为。

这意味着您定义了它,但没有在当前类中使用它(至少显式使用(。

如果在当前类中不需要它,只需删除此声明即可。

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

但是,还有另一种使用静态className()方法传递类的方法:

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

如果您将使用它,则该 IDE 通知将消失,因为现在您正在显式引用该类。

官方文档:

  • yii''base''Object className((