Yii2重写核心类-未找到类
我尝试通过以下方法扩展BaseHtml类 但是找不到BaseHtml扩展类Yii2重写核心类-未找到类,yii2,yii2-advanced-app,Yii2,Yii2 Advanced App,我尝试通过以下方法扩展BaseHtml类 但是找不到BaseHtml扩展类 namespace common\components; class Html extends \yii\helpers\BaseHtml { } 这就是错误: Class 'yii\helpers\BaseHtml' not found 我错在哪里 更新 我试图复制位于Helpers中的Html.php文件,但仍然是一样的 <?php /** * @link http://www.yiiframework
namespace common\components;
class Html extends \yii\helpers\BaseHtml {
}
这就是错误:
Class 'yii\helpers\BaseHtml' not found
我错在哪里
更新
我试图复制位于Helpers中的Html.php文件,但仍然是一样的
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\helpers;
/**
* Html provides a set of static methods for generating commonly used HTML tags.
*
* Nearly all of the methods in this class allow setting additional html attributes for the html
* tags they generate. You can specify, for example, `class`, `style` or `id` for an html element
* using the `$options` parameter. See the documentation of the [[tag()]] method for more details.
*
* For more details and usage information on Html, see the [guide article on html helpers](guide:helper-html).
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class Html extends BaseHtml
{
}
找到解决方案
我重构了覆盖文件,phpsform将vendor/yiisoft/yii2/classe.php中BaseHtml的路径更改为BaseHtml。php应位于/vendor/yiisoft/yii2/helpers/folder下。 如果没有,您需要更新您的供应商或尝试将文件BaseHtml.php复制到yii2 repo的Yi2/helpers:
希望能有所帮助。复制的类也就不足为奇了:这需要一个
use
语句。但第一个问题很奇怪。如何使用Html类?您是否已将您的类添加到Yii::$classMap
?解决方案应作为可接受的答案提供,而不是通过标记问题的title
字段!感谢您的时间,robsch,使用声明不是必需的,而且是正确的,只是扩展是错误的,必须是Html而不是BaseHtml。问题是关于覆盖文件,我用solutionDevDio编辑了我的问题,我不知道如何让自己熟悉StackOverflow。
vendor/yiisoft/yii2/helpers/Html.php