Link.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace addons\TinyShop\common\widgets\link;
  3. use Yii;
  4. use yii\helpers\Json;
  5. use common\helpers\Html;
  6. /**
  7. * Class Link
  8. *
  9. * $form->field($model, 'link')->widget(addons\TinyShop\common\widgets\link\Link::class);
  10. *
  11. * @package addons\TinyShop\common\widgets\link
  12. * @author jianyan74 <751393839@qq.com>
  13. */
  14. class Link extends \yii\widgets\InputWidget
  15. {
  16. /**
  17. * @return string
  18. * @throws \Exception
  19. */
  20. public function run()
  21. {
  22. $value = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
  23. $name = $this->hasModel() ? Html::getInputName($this->model, $this->attribute) : $this->name;
  24. empty($value) && $value = [];
  25. // 不引入 vue
  26. Yii::$app->params['notRequireVue'] = true;
  27. return $this->render('index', [
  28. 'value' => Json::encode($value),
  29. 'name' => $name,
  30. 'title' => $value['title'] ?? '',
  31. 'merchant_id' => Yii::$app->services->merchant->getNotNullId()
  32. ]);
  33. }
  34. }
粤ICP备19079148号