I don't know what's wrong with my code because i think, i have following all the step from github krivochenko/yii2-cropper But button to cropping or delete upload doesn't work and and also the css displayed on the form is not neat like this :
i'm not see any error in console, and i want to include the code i made :
this is in view :
use budyaga\cropper\Widget;
<div class="form-group col-sm-8 col-md-8 col-lg-6">
<?= $form->field($model, 'imageFile')->widget(Widget::className(), [
'uploadUrl' => Url::toRoute($uploadPhoto['url']),
]) ?>
</div>
then this is in controller:
return $this->render('input', [
'model' => $model,
'uploadPhoto' => [
'class' => 'budyaga\cropper\actions\UploadAction',
'url' => 'content/user/create',
'path' => $this->baseApp.'/files/uploads',
]
]);
So what's wrong with this code?
finally, i can understand what wrong with my code.
I need to adjust css from this widget in my own with add param in widget input form.:
<?= $form->field($model, 'imageFile')->widget(Widget::className(), [
'uploadUrl' => Url::toRoute($uploadPhoto['url']),
'cropAreaHeight' => 'auto' //here
]) ?>
i put Upload Photo index into create action, Upload Photo should be placed in function action(general) like this:
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'uploadPhoto' => [
'class' => 'budyaga\cropper\actions\UploadAction',
'url' => 'dir_to_save_the_result_of_crop',
'path' => 'path_to_save_the_result_of_crop',
]
];
}
And this widget krivochenko/yii2-cropper can works also really easy to use in yii2
Related
In my Yii2 Framework project I have a form where I am using Kartik Editable Widget for input. There is two rows with this widget. When I open my first input and entering something, in my console appears error message like - 'Uncaught TypeError: elem.replace is not a function'. But second input works as I expect. As I understood there is some conflict in jQuery but I can not figure out where. Both 'delivery_comment' and 'loyality_comment' are varchar(250). Here is code of my View file:
<div class="col-md-4">
<?= Html::activeLabel($model, 'delivery_comment') ?>
<br>
<?= Editable::widget([
'model' => $model,
'attribute'=>'delivery_comment',
'inputType' => Editable::INPUT_TEXTAREA,
'formOptions' => [
'id' => 'form-delivery-'.$model->stor_number,
],
'options' => [
'class'=>'form-control',
'rows'=>5,
],
]);
?>
<?= Html::error($model, 'delivery_comment') ?>
</div>
<div class="col-md-4">
<?= Html::activeLabel($model, 'loyality_comment') ?>
<br>
<?= Editable::widget([
'model' => $model,
'attribute'=>'loyality_comment',
'inputType' => Editable::INPUT_TEXTAREA,
'formOptions' => [
'id' => 'form-loyality-'.$model->stor_number,
],
'options' => [
'class'=>'form-control',
'rows'=>5,
],
]);
?>
<?= Html::error($model, 'loyality_comment') ?>
</div>
Thanks in advance for any help.
P.S. Here is the full error message:
Uncaught TypeError: elem.replace is not a function
at Function.buildFragment (jquery.js:5114)
at jQuery.fn.init.domManip (jquery.js:5387)
at jQuery.fn.init.append (jquery.js:5218)
at jQuery.fn.init. (jquery.js:5333)
at jQuery.access (jquery.js:3491)
at jQuery.fn.init.html (jquery.js:5300)
at showError (editable.js:93)
at Object.error (editable.js:168)
at fire (jquery.js:3099)
at Object.fireWith [as rejectWith] (jquery.js:3211)
I got this bug only in first cell of the table, and Make fake cell.
This is not good but it works.
'class' => 'kartik\grid\EditableColumn',
'attribute' => 'fakeColumn',
'filterOptions' => ['class' => 'hide'],
'headerOptions' => ['class' => 'hide'],
'contentOptions' => ['class' => 'hide'],
I created a dropdownList for my project and I made the field as required in my model rules.
In view
use app\models\Constituency;
use yii\helpers\ArrayHelper;
use kartik\widgets\Select
<?php
$constituency=Constituency::find()->all();
$listData=ArrayHelper::map($constituency,'constituency','constituency');
?>
<?php
echo '<label class="control-label">Constituency</label>';
echo Select2::widget([
'model' => $model,
'attribute' => 'place',
'data' => $listData,
'options' => ['placeholder' => 'Select a constituency'],
'pluginOptions' => [
'allowClear' => true
],
]);
?>
In Models
['place', 'required','message'=>'Place is required'],
Even I tired to give a custom error message for the field,But everything I tried was failed.
I am attaching the screenshot of the page here.
As you can see its shows no required error.
Can anyone tell me what I am missing??
Use active field widget:
<?= $form->field($model, 'place')->widget(Select2::className(), [
'data' => $listData,
'options' => ['placeholder' => 'Select a constituency'],
'pluginOptions' => ['allowClear' => true],
]) ?>
How can I make a URL in DetailView row on yii2?
For example: blow code is something like custom row in GridView, but as you know DetailView is different and this code not works in DetailView.
<?= DetailView::widget([
'model' => $model,
'attributes' => [
[
'attribute' => 'file',
'label' => 'File',
'fomat' => 'Url', // I want something like this
'value' => Html::a('Dowaload The File', ['files/uloads']),
],
])
I have not found my problem's solution in similar questions.
Please help me to create Url row in DetailView.
You can use either the shorthand url formatter (that does not provide much customization options):
'attributes' => [
'file:url'
]
Or the raw format with which you can customize everything:
'attributes' =>[
[
'attribute'=>'file',
'label'=>'File',
'format'=>'raw',
'value'=>Html::a('Download the File', url),
],
...
You can create a download link to the file inside the detail view in the following way, I am assuming that the file path for download is coming from the database field file.
<?= DetailView::widget([
'model' => $model,
'attributes' => [
[
'attribute' => 'file',
'label' => 'File',
'value' => function ($model) {
return Html::a('Download The File', $model->file);
},
'format' => 'raw',
],
]
]);
I'm using a module yii2-images by CostaRico for my application and it works fine. This module can rename, crop and store images in a specific folders and it does job well. But when I try to render an image in my view all I can get is a path like this:
/yii2images/images/image-by-item-and-alias?item=Product1&dirtyAlias=b6e73413ff-1_50x50.jpg
This is the render widget code:
<?php $imageOne = $model->getImage(); ?>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'title',
'alias',
'price',
[
'attribute' => 'imageOne',
'value' => '<img src="' . $imageOne->getUrl('50x50') . '">',
'format' => 'raw',
],
'status',
'frontpage',
'primary_category',
'sku',
'short_desc:ntext',
'full_desc:html',
],
]) ?>
Normally, I would wrap it with img tag and the image should be rendered. However, it won't happen. Browser shows Status 200, OK. Image does exists and if I will use a path like below I can see it in my view.
/upload/cache/Products/Product1/b6e73413ff-1_50x50.jpg
Also, I've tried to render this image using DetailView widget adding format options like raw and html but no luck.
I've seen some guys on YouTube using this modules and they had the same kind of path with parameters and everything is ok.
What could be the problem? Is it some routing issue? I haven't changed the original module.
Routs
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
'category/<alias>/page-<page:\d+>' => 'category/view',
'category/<alias>' => 'category/view',
'product/<id:\d+>' => 'product/view',
'page/<alias>' => 'page/view',
'search' => 'category/search',
],
],
if you have RBAC or limited access for guest
'as access' => [
...
'yii2images/*',
],
and route
'image' => 'yii2images/images/image-by-item-and-alias',
i have a view folder called eventos in Yii2. This view is an image gallery.
The _view2.php is for display of the images to general public. It works quite well.
But now i want to create a globalsearch input text inside _view2.php.
There i have already a GridView widget for display the images, but i don't want to use the $searchmodel boxes so i disable them.
What i want is to render the _search.php file with just one input field, inside the _view2.php file
My problem is in rendering the _search.php inside the _view2.php file.
Here is the code for _view2.php:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'showOnEmpty'=>false,
'summary'=>'',
'showFooter'=>false,
'showHeader' => false,
'bordered' => false,
'striped' => false,
'hover' => true,
//'options' => ['class' => 'grid-view'],
//'layout' => "{summary}\n{items}\n{pager}",
'columns' => [
['class' => 'yii\grid\SerialColumn'],
//'id',
//'nome',
'descricao',
'data',
// No model -> getImageurl()
[
'label' => '',
'format' => 'raw',
'value'=> function($data) { return Html::a(Html::img($data->imageurl, ['width'=>'300', 'height' => "170"]), $data->foto); },
],
[
'label' => '',
'format' => 'raw',
'value'=> function($data) { return Html::a(Html::img($data->imageurl2, ['width'=>'300', 'height' => "170"]), $data->foto2); },
],
['class' => 'yii\grid\ActionColumn', 'template' => ''],
],
]); ?>
And i need to render the _search.php inside the _view2.php.
Code for _search.php:
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'globalsearch') ?>
Any ideas?
SOLVED.
_view2.php code:
use yii\base\view;
echo $this->render('_search', array('model'=>$searchModel));
You can use renderPartial to display a partil view inside another
For example adding this:
<?php echo $this->renderPartial('_search', array('model'=>$model)); ?>
This is an example that is generated with gii by the way
Here is the code of a file view/create.php:
<?php
/* #var $this EventsController */
/* #var $model Events */
$this->breadcrumbs=array(
'Events'=>array('index'),
'Create',
);
$this->menu=array(
array('label'=>'List Events', 'url'=>array('index')),
array('label'=>'Admin Events', 'url'=>array('admin')),
);
?>
<h1>Create Event</h1>
<?php echo $this->renderPartial('_form', array('model'=>$model)); ?>
As you can see the view 'create' loads the partial view '_form' that is the way you acomplish this. So you can reuse the _form view in another views like in the update view for example.