sereja3578 / yii2-documents-widget
包
dev-master
2021-01-27 20:20 UTC
Requires
- php: >=7.3.0
- kartik-v/yii2-krajee-base: *
- porcelanosa/yii2-magnific-popup: master-dev
- yiisoft/yii2: 2.*
This package is auto-updated.
Last update: 2024-09-28 04:59:37 UTC
README
安装时,请将以下代码添加到 composer.json 中
"sereja3578/yii2-documents-widget": "dev-master"
为了基本使用,需要在视图中添加以下代码
<?= DocumentWidget::widget([
'documentGridId' => '#document-grid-container',
'urlForAjax' => Url::toRoute('/user/user-document/get-document-url'),
'title' => Yii::t('documents', 'Скан документа'),
'options' => [
'imageContainer' => '.document-image-div',
'documentImage' => [
'class' => 'magnific-image'
]
]
]); ?>
获取文件路径的方法可能如下所示
/**
* Метод для ajax запроса в виджете
*
* @param $id
* @throws NotFoundHttpException
* @return string
*/
public function actionGetDocumentUrl(int $id) : string
{
$model = $this->findModel($id);
$file = $model->getFile()->one();
Yii::$app->response->format = Response::FORMAT_JSON;
return $file ? ['url' => $file->getUrl()] : ['error' => Yii::t('user', 'Нет файла')];
}
即对于 user,有一个与其关联的文件表,可以从中获取文件的 URL。