Fail email validation on Kartik MaskedInput for Yii2 - yii2

i have a form validation implemented with Kartik MaskedInput on Yii2 Framework, like this:
echo $form->field($model, 'email')->widget(MaskedInput::className(), [
'clientOptions' => [
'alias' => 'email',
]
])
Image Code Form
The case is who validation is not correct.
How do i validate this removing the "#_._".
I think who the correct would be set its wrong, like this:
Image fake wrong

Related

How to add a dot(.) in the url in yii2?

I was trying to add a dot in my URL in yii2. I am using Url rules for this.
Right now my URL looks like this.
http://localhost:8000/user/auth_key
But i want to change it to this
http://localhost:8000/.user/auth_key
My url-rules.php file looks like this.
<?php
return [
'enablePrettyUrl' => true,
'rules' => [
'user/auth_key' => 'user/authentication'
]
];
?>
without the dot(.) the URL works fine. But I need a dot(.) in URL.
Does yii2 allow us to do this? How can I achieve this?
Any suggestions or help would be really appreciated.
Yes, Yii will treat the pattern '.user/auth_key' as plain text, you can use it directly.
The full rule would be:
return [
'enablePrettyUrl' => true,
'rules' => [
'.user/auth_key' => 'user/authentication'
]
];

Why my listview not found any record in yii2?

I have a dataprovider to search a world but my listview does not display any record? How can i send this query object to listview?
every thing in my webpage is worked very good but at the output my list view show "not found any result" this mean my list view code is no have problem . problem is in my dataprovider and this query beacuse i customize that
my controller:
$query = new Query();
$dataProvidersearch=new ActiveDataProvider([
'query'=>$query->from('tbl_post')->Where(['like', 'title', $search])-
>andWhere(['like', 'en_title', $search])->andWhere(['like', 'content', $search])->andWhere(['like', 'en_content', $search]),
]);
this is my list view in my view:
$posts = $model->getModels();
echo ListView::widget([
'dataProvider'=>$posts,
'itemView'=>'search',
'summary' => '',
'itemOptions' => [
'tag' => false
],
]);
I'm not sure you have enough code here for someone to help. Even something simple like a listview could consist of a view, a controller, and two model files and your code could be failing at any of these points. You may have simply forgot to include the listview library at the top of your view, but we can't see that in your current example.
What I would recommend is using Gii to generate a listview. It is simple to do and once you have it created, you can study the code to see where you went wrong. You can see how to get started generating code with Gii here: http://www.yiiframework.com/doc-2.0/guide-start-gii.html
ANSWER FROM COMMENTS: Replace andWhere with orWhere, no results are found because no record can match 'title' and 'en_title' and 'content' and 'en_content'.
You are submitting $posts as 'dataProvider' while it should be dataProvidersearch
Instead of:
$posts = $model->getModels();
echo ListView::widget([
'dataProvider'=>$posts,
'itemView'=>'search',
'summary' => '',
'itemOptions' => [
'tag' => false
],
];
Should be:
$posts = $model->getModels();
echo ListView::widget([
'dataProvider'=>$dataProvidersearch,
'itemView'=>'search',
'summary' => '',
'itemOptions' => [
'tag' => false
],
];

yii2 SluggableBehavior is applied to only emty slug field

I am using SluggableBehavior in such way
public function behaviors()
{
return [
[
'class' => SluggableBehavior::className(),
'attribute' => 'name',
'slugAttribute' => 'alias',
],
];
}
It works nice If field 'alias' in form is empty.
How to ignore this behaviors If field alias is not empty on form submitting ?
thanks in advance !
Add 'immutable'=>true in the behavour config.
The behaviour works in such way, that if the slugAttribute is not empty when immutable is on, that attribute will not be changed.
Try something like:
Configure this behavior with specific name:
return [
'slug' => [
'class' => SluggableBehavior::className(),
'attribute' => 'name',
'slugAttribute' => 'alias',
],
];
In controller load attributes from the form (before validation).
Check if alias attribute is empty.
If it is not - detach this behavior ($this->detachBehavior('slug')).
Validate model.

How do I add Kartik ActiveField on Kartik DetailView?

I'm using Kartik's awesome extension called DetailView. I'd like to add the Kartik widget called ActiveField to the DetailView. What is the proper way to use the ActiveField widget in the DetailView widget?
The code I'm using generates the error First parameter must either be an object or the name of an existing class. According to Kartik's documentation, any widget (not just the DetailView widgets) can be used. What is the proper way to do that?
$attributes = [
['attribute' => 'definition_summary',
'format' => 'raw',
'type'=>DetailView::INPUT_WIDGET,
'widgetOptions'=>[
'class'=>ActiveField::className(),
'addon' => ['prepend' => ['content' => '#']],
],
];
echo DetailView::widget([
'model' => $model,
'attributes' => $attributes,
]);

Missing features in Ckeditor

Using yii2-ckeditor-widget but missing upload tab and browser, how can I integrate those features ..
I have tried the 2amigos CKEditor Widget for editor.
But cant upload the image though I paste the url of the image.
any solution to get those features in yii2 ?
You need to define your Upload Action:
<?= $form->field($model, 'content')->widget(CKEditor::className(), [
'options' => ['rows' => 6],
'preset' => 'basic'
'clientOptions' => [
'filebrowserUploadUrl' => 'site/url'
]
]) ?>
And there should be your handler for file uploads on this route (http://hosannahighertech.co.tz/blog/mweledi/11-Yii2-CKEditor-and-Images-Upload).
You also can use file manager plugin which have integration with ckeditor:
https://github.com/MihailDev/yii2-elfinder
https://github.com/MihailDev/yii2-ckeditor