关于Yii :: $ app->

时间:2016-06-17 13:37:28

标签: php yii2 yii2-advanced-app yii2-module

我在我的应用程序中实现了句柄滑块的yii2模块,项目的基础结构是yii2高级模板。 我是一个类图像,它扩展了由gii生成的另一个模型类, Images.php

<?php

 namespace common\modules\sliders\models;

 use Yii;
 use common\modules\sliders\models\base\Images as Im;

 /**
  * This is the model class for table "images".
  *
  */
 class Images extends Im
 {
    const UPLOAD_URL = Yii::$app->getModule('sliders');
 }

costant UPLOAD_URL将是我上传图像的路径,此值存储在我的模块的配置参数中,因此配置模块以便在另一个应用程序中使用更加简单。 当我创建一个Images对象的实例时,我收到的奇怪错误是:

  

语法错误,意外&#39; $ app&#39; (T_VARIABLE),期待标识符(T_STRING)或类(T_CLASS)

感兴趣的这一行:

const UPLOAD_URL = Yii::$app->getModule('sliders');

为什么会这样?

P.s。:我知道UPLOAD_URL以这种方式不接受配置参数的值,但是我已经错误地停止了。

感谢。

1 个答案:

答案 0 :(得分:1)

您不能将值以值的形式分配给常量

你可以这样做

const UPLOAD_URL ='yourpath\yourmodul\;

或者如果你需要使用函数

public  function getUploadUrl() {
  return Yii::$app->getModule('sliders');
}