您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Yii2 为何无法通过变量来创建对象呢?

2024/2/28 18:33:35发布17次查看
use root\modules\article\models\articlesearch;$model='articlesearch';$searchmodel=new $model();

提示未找到
php fatal error – yii\base\errorexceptionclass 'articlesearch' not found

是使用了命名空间的原因吗?
回复内容: use root\modules\article\models\articlesearch;$model='articlesearch';$searchmodel=new $model();

提示未找到
php fatal error – yii\base\errorexceptionclass 'articlesearch' not found

是使用了命名空间的原因吗?
$model='root\modules\article\models\articlesearch';$searchmodel=new $model();
请试试这么写
or
use root\modules\article\models\articlesearch;$model= articlesearch::classname();$searchmodel=new $model();
通过变量创建类的时候,一定要包含类全名,不能通过命名空间替代。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product