本文整理汇总了PHP中yii\helpers\Html::activeFileInput方法的典型用法代码示例。如果您正苦于以下问题:PHP Html::activeFileInput方法的具体用法?PHP Html::activeFileInput怎么用?PHP Html::activeFileInput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\Html
的用法示例。
在下文中一共展示了Html::activeFileInput方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* @inheritdoc
*/
public function run()
{
if ($this->hasModel()) {
$field = Html::activeFileInput($this->model, $this->attribute, $this->options);
} else {
$field = Html::fileInput($this->name, $this->value, $this->options);
}
echo $this->renderTemplate($field);
$this->registerPlugin();
}
示例2: run
public function run()
{
if (is_null($this->imageOptions)) {
$this->imageOptions = ['class' => 'img-responsive'];
}
$this->imageOptions['id'] = Yii::$app->getSecurity()->generateRandomString(10);
$inputField = Html::getInputId($this->model, $this->attribute);
$class = \yii\helpers\StringHelper::basename(get_class($this->model)) . 'Cutter';
echo Html::beginTag('div', ['class' => 'image-cutter', 'id' => $inputField . '-cutter']);
echo Html::activeFileInput($this->model, $this->attribute);
echo Html::hiddenInput($class . '[' . $this->attribute . ']', $this->model->{$this->attribute});
$previewImage = Html::beginTag('div', ['class' => 'img-container']);
$previewImage .= Html::tag('span', '', ['class' => 'helper']);
$previewImage .= Html::tag('span', Yii::t('sadovojav/cutter/cutter', 'Click to upload image'), ['class' => 'message']);
$previewImage .= Html::img($this->model->{$this->attribute} ? $this->model->{$this->attribute} : null, ['class' => 'preview-image']);
$previewImage .= Html::endTag('div');
echo Html::label($previewImage, Html::getInputId($this->model, $this->attribute), ['class' => 'dropzone']);
echo Html::checkbox($class . '[' . $this->attribute . '-remove]', false, ['label' => Yii::t('sadovojav/cutter/cutter', 'Remove')]);
Modal::begin(['header' => Html::tag('h4', Yii::t('sadovojav/cutter/cutter', 'Cutter'), ['class' => 'modal-title']), 'closeButton' => false, 'footer' => $this->getModalFooter($inputField), 'size' => Modal::SIZE_LARGE]);
echo Html::beginTag('div', ['class' => 'image-container']);
echo Html::img(null, $this->imageOptions);
echo Html::endTag('div');
echo Html::tag('br');
echo Html::beginTag('div', ['class' => 'row']);
echo Html::beginTag('div', ['class' => 'col-md-2']);
echo Html::label(Yii::t('sadovojav/cutter/cutter', 'Aspect ratio'), $inputField . '-aspectRatio');
echo Html::textInput($class . '[' . $this->attribute . '-aspectRatio]', isset($this->cropperOptions['aspectRatio']) ? $this->cropperOptions['aspectRatio'] : 0, ['id' => $inputField . '-aspectRatio', 'class' => 'form-control']);
echo Html::endTag('div');
echo Html::beginTag('div', ['class' => 'col-md-2']);
echo Html::label(Yii::t('sadovojav/cutter/cutter', 'Angle'), $inputField . '-dataRotate');
echo Html::textInput($class . '[' . $this->attribute . '-cropping][dataRotate]', '', ['id' => $inputField . '-dataRotate', 'class' => 'form-control']);
echo Html::endTag('div');
echo Html::beginTag('div', ['class' => 'col-md-2']);
echo Html::label(Yii::t('sadovojav/cutter/cutter', 'Position') . ' (x)', $inputField . '-dataX');
echo Html::textInput($class . '[' . $this->attribute . '-cropping][dataX]', '', ['id' => $inputField . '-dataX', 'class' => 'form-control']);
echo Html::endTag('div');
echo Html::beginTag('div', ['class' => 'col-md-2']);
echo Html::label(Yii::t('sadovojav/cutter/cutter', 'Position') . ' (y)', $inputField . '-dataY');
echo Html::textInput($class . '[' . $this->attribute . '-cropping][dataY]', '', ['id' => $inputField . '-dataY', 'class' => 'form-control']);
echo Html::endTag('div');
echo Html::beginTag('div', ['class' => 'col-md-2']);
echo Html::label(Yii::t('sadovojav/cutter/cutter', 'Width'), $inputField . '-dataWidth');
echo Html::textInput($class . '[' . $this->attribute . '-cropping][dataWidth]', '', ['id' => $inputField . '-dataWidth', 'class' => 'form-control']);
echo Html::endTag('div');
echo Html::beginTag('div', ['class' => 'col-md-2']);
echo Html::label(Yii::t('sadovojav/cutter/cutter', 'Height'), $inputField . '-dataHeight');
echo Html::textInput($class . '[' . $this->attribute . '-cropping][dataHeight]', '', ['id' => $inputField . '-dataHeight', 'class' => 'form-control']);
echo Html::endTag('div');
echo Html::endTag('div');
Modal::end();
echo Html::endTag('div');
$options = ['inputField' => $inputField, 'useWindowHeight' => $this->useWindowHeight, 'cropperOptions' => $this->cropperOptions];
$options = Json::encode($options);
$this->view->registerJs('jQuery("#' . $inputField . '").cutter(' . $options . ');');
}
示例3: run
/**
* @inheritdoc
*/
public function run()
{
$width = null;
if ($this->thumbsEnabled) {
$filename = $this->behavior->getThumbFilePath($this->attribute, $this->thumbProfileName);
} else {
$filename = $this->behavior->getUploadedFilePath($this->attribute);
}
if (is_readable($filename)) {
list($width) = getimagesize($filename);
} else {
Yii::warning("Unable to read file: '{$filename}' referenced by '{$this->attribute}' in model {$this->model->className()}");
if (empty($this->previewOptions['style'])) {
$this->previewOptions['style'] = '';
}
$this->previewOptions['style'] .= ';display: none;';
}
$previewOptions = ArrayHelper::merge(['id' => $this->id . '-thumb', 'width' => $width], $this->previewOptions);
if (empty($previewOptions['class'])) {
$previewOptions['class'] = '';
}
$previewOptions['class'] .= ' img-responsive img-thumbnail';
if (isset($this->model->attributeLabels()[$this->attribute]) and !isset($previewOptions['alt'])) {
$previewOptions['alt'] = $this->model->attributeLabels()[$this->attribute];
}
if ($this->thumbsEnabled) {
$url = $this->behavior->getThumbFileUrl($this->attribute, $this->thumbProfileName);
} else {
$url = $this->behavior->getImageFileUrl($this->attribute);
}
Html::addCssStyle($previewOptions, "background-image: url({$url})");
$image = Html::tag('div', '', $previewOptions);
$fileInput = Html::activeFileInput($this->model, $this->attribute, ['id' => $this->id . '-input'] + $this->options);
echo $this->render('index', compact('image', 'fileInput'));
$this->getView()->registerJs(";(function(\$){\n var widget = \$('#{$this->id}');\n var fileInput = widget.find('input[type=file]');\n var preview = \$('#{$previewOptions['id']}');\n var button = fileInput.closest('.image-up-input-button');\n\n fileInput.on('change', function() {\n var selectedFile = this.files[0];\n\n if (selectedFile) {\n var reader = new FileReader();\n reader.readAsDataURL(selectedFile);\n reader.onload = function (e) {\n preview.css('background-image', 'url(' + e.target.result + ')');\n }\n\n preview.show();\n }\n });\n\n})(jQuery);");
$this->getView()->registerCss(<<<CSS
#{$previewOptions['id']} {
background-position: center;
background-repeat: no-repeat;
background-size: contain;
}
CSS
);
}
示例4: run
/**
* @inheritdoc
*/
public function run()
{
$input = $this->hasModel() ? Html::activeFileInput($this->model, $this->attribute, $this->options) : Html::fileInput($this->name, $this->value, $this->options);
echo $this->render('uploadButton', ['input' => $input]);
$this->registerClientScript();
}
示例5: run
public function run()
{
/* @var $model ActiveRecord|ImageUploaderBehavior */
$model = $this->model;
/* @var $behavior ImageUploaderBehavior */
$behavior = $model->geImageBehavior();
$wigetId = $this->id;
$img_hint = '<div class="hint-block">';
$img_hint .= 'Поддерживаемые форматы: ' . $behavior->getImageConfigParam('fileTypes') . '.
Максимальный размер файла: ' . ceil($behavior->getImageConfigParam('maxFileSize') / 1024 / 1024) . 'мб.';
$img_hint .= '</div><!-- /.hint-block -->';
$imageVal = $model->getAttribute($behavior->getImageConfigParam('imageAttribute'));
if (!$model->isNewRecord && !empty($imageVal)) {
$img_hint .= '<div id="' . $wigetId . '" class="row">';
$img_hint .= '<div class="col-md-12">';
$img_hint .= Html::img($this->imageSrc, ['class' => 'pull-left uploaded-image-preview']);
// $img_hint .= '<div class="pull-left" style="margin-left: 5px;">';
$img_hint .= '<div class="btn-group-vertical pull-left" style="margin-left: 5px;" role="group">';
$img_hint .= Html::a('Delete <i class="glyphicon glyphicon-trash"></i>', '#', ['onclick' => new JsExpression('
if (!confirm("Вы действительно хотите удалить изображение?")) {
return false;
}
$.ajax({
type: "post",
cache: false,
url: "' . Url::to($this->deleteUrl) . '",
success: function() {
$("#' . $wigetId . '").remove();
}
});
return false;
'), 'class' => 'btn btn-danger']);
if (!empty($this->cropUrl)) {
Yii::$app->response->headers->add('Access-Control-Allow-Origin', '*');
$pluginOptions = $this->cropPluginOptions;
$validatorParams = $behavior->getImageConfigParam('imageValidatorParams');
if (isset($validatorParams['minWidth'])) {
$pluginOptions['minCropBoxWidth'] = $validatorParams['minWidth'];
}
if (isset($validatorParams['minHeight'])) {
$pluginOptions['minCropBoxHeight'] = $validatorParams['minHeight'];
}
$img_hint .= Cropper::widget(['modal' => true, 'cropUrl' => $this->cropUrl, 'image' => ImageUploaderBehavior::addPostfixToFile($model->getImageSrc(), '_original'), 'aspectRatio' => $behavior->getImageConfigParam('aspectRatio'), 'pluginOptions' => $pluginOptions, 'ajaxOptions' => ['success' => new JsExpression(<<<JS
function(data) {
// Refresh image src value to show new cropped image
var img = \$("#{$wigetId} img.uploaded-image-preview");
img.attr("src", img.attr("src").replace(/\\?.*/, '') + "?" + new Date().getTime());
}
JS
)]]);
}
$img_hint .= '</div><!-- /.btn-group -->';
$img_hint .= '</div><!-- /.col-md-12 -->';
$img_hint .= '</div><!-- /.row -->';
}
$imgAttr = $behavior->getImageConfigParam('imageAttribute');
return Html::activeFileInput($model, $imgAttr) . $img_hint;
}
示例6: run
/**
* @inheritdoc
*/
public function run()
{
if ($this->enableClientScript) {
$view = $this->getView();
JasnyBootstrapAsset::register($view);
}
return implode("\n", [Html::beginTag('div', ['class' => 'fileinput fileinput-new input-group', 'data-provides' => 'fileinput']), Html::beginTag('div', ['class' => 'form-control', 'data-trigger' => 'fileinput']), Html::tag('i', '', ['class' => 'glyphicon glyphicon-file fileinput-exists']), Html::tag('span', '', ['class' => 'fileinput-filename']), Html::endTag('div'), Html::beginTag('span', ['class' => 'input-group-addon btn btn-default btn-file']), Html::tag('span', $this->selectButtonTitle, ['class' => 'fileinput-new']), Html::tag('span', $this->changeButtonTitle, ['class' => 'fileinput-exists']), Html::activeFileInput($this->model, $this->attribute, $this->options), Html::endTag('span'), Html::a($this->removeButtonTitle, '#', ['class' => 'input-group-addon btn btn-default fileinput-exists', 'data-dismiss' => 'fileinput']), Html::endTag('div')]) . "\n";
}
示例7: run
/**
* {@inheritdoc}
*/
public function run()
{
if ($this->hasModel()) {
echo Html::activeFileInput($this->model, $this->attribute, $this->options);
} else {
echo Html::fileInput($this->name, $this->value, $this->options);
}
$this->registerClientScript();
}
示例8: getInputField
/**
* @param string $attribute
*
* @return string
*/
public function getInputField($attribute)
{
if ($this->inputType == 'textArea') {
return Html::activeTextarea($this->model, $attribute, $this->inputOptions);
} elseif ($this->inputType == 'file') {
return Html::activeFileInput($this->model, $attribute, $this->inputOptions);
} else {
return Html::activeTextInput($this->model, $attribute, $this->inputOptions);
}
}
示例9: renderInput
/**
* Renders the input
*
* @return string
*/
protected function renderInput()
{
$options = ArrayHelper::merge($this->options, ['class' => ' ' . $this->id, 'data-type' => $this->attribute]);
$script = '$(function () {
$(\'input.' . $this->id . '\').dropzone({
\'value\': \'' . $this->value . '\'
})
});';
$this->view->registerJs($script, View::POS_READY);
return Html::activeFileInput($this->model, $this->attribute, $options);
}
示例10: run
public function run()
{
$value = $this->model->{$this->attribute};
if ($value) {
echo Html::img(rtrim($this->imagePrefix, '/') . '/' . $value, ['height' => 200, 'class' => 'thumbnail']);
}
echo Html::activeFileInput($this->model, $this->attribute);
if ($value) {
echo Html::activeHiddenInput($this->model, $this->attribute);
}
}
示例11: run
public function run()
{
if (is_null($this->imageOptions)) {
$this->imageOptions = ['class' => 'img-responsive'];
}
$this->imageOptions['id'] = Yii::$app->getSecurity()->generateRandomString(10);
$inputField = Html::getInputId($this->model, $this->attribute);
echo Html::beginTag('div', ['id' => $inputField . '-cutter']);
echo Html::activeFileInput($this->model, $this->attribute, ['class' => 'hide']);
echo Html::beginTag('div', ['class' => 'preview-pane', 'style' => $this->model->{$this->attribute} ? 'display:block' : 'display:none']);
echo Html::beginTag('div', ['class' => 'preview-container']);
echo Html::img($this->previewImgSrc ? $this->previewImgSrc : $this->model->{$this->attribute}, ['class' => 'preview-image ' . $this->previewImgClass]);
echo Html::endTag('div');
echo Html::endTag('div');
echo Html::checkbox($this->attribute . '-remove', false, ['label' => Yii::t('davfervaz/cutter', 'Remove photo')]);
Modal::begin(['header' => Html::tag('h4', Yii::t('davfervaz/cutter', 'Select the cut area')), 'closeButton' => [], 'footer' => $this->getModalFooter($inputField), 'size' => Modal::SIZE_LARGE]);
echo Html::beginTag('div', ['class' => 'image-container']);
echo Html::img(null, $this->imageOptions);
echo Html::endTag('div');
echo Html::tag('br');
echo Html::beginTag('div', ['class' => 'row']);
echo Html::beginTag('div', ['class' => 'col-md-2']);
echo Html::label(Yii::t('davfervaz/cutter', 'ASPECT_RATIO'), $inputField . '-aspectRatio');
echo Html::textInput($this->attribute . '-aspectRatio', isset($this->cropperOptions['aspectRatio']) ? $this->cropperOptions['aspectRatio'] : 0, ['id' => $inputField . '-aspectRatio', 'class' => 'form-control']);
echo Html::endTag('div');
echo Html::beginTag('div', ['class' => 'col-md-2']);
echo Html::label(Yii::t('davfervaz/cutter', 'ANGLE'), $inputField . '-dataRotate');
echo Html::textInput($this->attribute . '-cropping[dataRotate]', '', ['id' => $inputField . '-dataRotate', 'class' => 'form-control']);
echo Html::endTag('div');
echo Html::beginTag('div', ['class' => 'col-md-2']);
echo Html::label(Yii::t('davfervaz/cutter', 'POSITION') . ' (X)', $inputField . '-dataX');
echo Html::textInput($this->attribute . '-cropping[dataX]', '', ['id' => $inputField . '-dataX', 'class' => 'form-control']);
echo Html::endTag('div');
echo Html::beginTag('div', ['class' => 'col-md-2']);
echo Html::label(Yii::t('davfervaz/cutter', 'POSITION') . ' (Y)', $inputField . '-dataY');
echo Html::textInput($this->attribute . '-cropping[dataY]', '', ['id' => $inputField . '-dataY', 'class' => 'form-control']);
echo Html::endTag('div');
echo Html::beginTag('div', ['class' => 'col-md-2']);
echo Html::label(Yii::t('davfervaz/cutter', 'WIDTH'), $inputField . '-dataWidth');
echo Html::textInput($this->attribute . '-cropping[dataWidth]', '', ['id' => $inputField . '-dataWidth', 'class' => 'form-control']);
echo Html::endTag('div');
echo Html::beginTag('div', ['class' => 'col-md-2']);
echo Html::label(Yii::t('davfervaz/cutter', 'HEIGHT'), $inputField . '-dataHeight');
echo Html::textInput($this->attribute . '-cropping[dataHeight]', '', ['id' => $inputField . '-dataHeight', 'class' => 'form-control']);
echo Html::endTag('div');
echo Html::endTag('div');
Modal::end();
echo Html::endTag('div');
$view = $this->getView();
CutterAsset::register($view);
$options = ['inputField' => $inputField, 'useWindowHeight' => $this->useWindowHeight, 'cropperOptions' => $this->cropperOptions];
$options = Json::encode($options);
$view->registerJs('jQuery("#' . $inputField . '").cutter(' . $options . ');');
}
示例12: run
/**
* @inheritdoc
*/
public function run()
{
if ($this->enableClientScript) {
$view = $this->getView();
JasnyBootstrapAsset::register($view);
}
$previewParams = ['class' => 'fileinput-preview thumbnail', 'data-trigger' => 'fileinput'];
if ($this->previewWidth and $this->previewHeight) {
$previewParams['style'] = 'width: ' . $this->previewWidth . 'px; height: ' . $this->previewHeight . 'px;';
}
return implode("\n", [Html::beginTag('div', ['class' => 'fileinput fileinput-new fileinput-image', 'data-provides' => 'fileinput']), Html::beginTag('div', $previewParams), Html::endTag('div'), Html::beginTag('div'), Html::beginTag('span', ['class' => 'btn btn-default btn-file']), Html::tag('span', $this->selectButtonTitle, ['class' => 'fileinput-new']), Html::tag('span', $this->changeButtonTitle, ['class' => 'fileinput-exists']), Html::activeFileInput($this->model, $this->attribute, $this->options), Html::endTag('span'), Html::a($this->removeButtonTitle, '#', ['class' => 'btn btn-default fileinput-exists', 'data-dismiss' => 'fileinput']), Html::endTag('div'), Html::endTag('div')]) . "\n";
}
示例13: run
public function run()
{
$this->registerAssets();
// Button to select & upload files
echo '<span class="btn btn-success fileinput-button"><span>Select files...</span>';
//The file input field used as target for the file upload widget
echo Html::activeFileInput($this->model, $this->attribute, ['name' => 'files[]']);
echo '</span>';
//The global progress bar
echo '<p>Upload progress</p>';
echo Progress::widget(['barOptions' => ['class' => 'progress-bar-success', 'aria-valuemax' => false, 'aria-valuemin' => false, 'role' => false, 'id' => 'bar'], 'options' => ['class' => false, 'id' => false]]);
//The list of files uploaded
echo '<p>Files uploaded:</p><ul id="files"></ul>';
}
示例14: run
/**
* Запустить
* процесс
* @return string
*/
public function run()
{
$content = '<div class="c-file-block">';
$content .= Html::activeFileInput($this->model, $this->attribute, ['class' => 'styled']);
if ($this->model->{$this->attribute} instanceof AttachFileModel && $this->model->{$this->attribute}->isExists()) {
$size = $this->model->{$this->attribute}->getSize();
$buttonId = Html::getInputId($this->model, $this->attribute) . '-button';
$content .= '<div class="img-preview file-block"><div class="c-info"><span>';
$content .= '<a href="' . $this->model->{$this->attribute}->getDownloadLink() . '" class="buttonS bGreen bWhite">Завантажити ' . $size . '</a></span>';
$content .= '<div class="delete-row"><a class="buttonS bRed nsubmit delete-file" href="javascript:void(0);" id="' . $buttonId . '">Видалити</a></div></div></div>';
$this->getView()->registerJs("\$('#{$buttonId}').click(function(){\$(this).closest('.c-file-block').find('input[type=\"hidden\"]').val('remove');})");
}
$content .= '</div>';
return $content;
}
示例15: imageField
/**
* Generates a form field.
* A form field is associated with a model and an attribute. It contains a label, an input and an error message
* and use them to interact with end users to collect their inputs for the attribute.
* @param Model $model the data model
* @param string $attribute the attribute name or expression. See [[Html::getAttributeName()]] for the format
* about attribute expression.
* @param array $options the additional configurations for the field object. These are properties of [[ActiveField]]
* or a subclass, depending on the value of [[fieldClass]].
* @return string the created ActiveField object
* @see fieldConfig
*/
public function imageField($model, $attribute, $options = [])
{
if ($model->{$attribute}) {
$src = '@web/' . $model->{$attribute};
} else {
$src = '@web/images/no_image.jpg';
}
$imageField = '';
$imageField .= Html::activeLabel($model, $attribute, ['class' => 'col-sm-12 control-label']);
$imageField .= Html::beginTag('label', ['for' => Html::getInputId($model, $attribute), ['class' => 'col-sm-8']]);
$imageField .= Html::img($src, $options);
$imageField .= Html::endTag('label');
$imageField .= Html::beginTag('span', ['class' => 'image-trash glyphicon glyphicon-remove-circle']);
$imageField .= Html::endTag('span');
$imageField .= Html::activeFileInput($model, $attribute, ['style' => 'display:none']);
$imageField .= Html::activeHiddenInput($model, 'removeImage', ['value' => '0']);
return $imageField;
}