How to put link around an Html::submitButton in yii2 framework - yii2

how to put link on an Html::submitButton in yii2.
I am creating an application and want a logout button under the login form which when gets clicked(only if the user is still logged in), will take the user to the logout action.
I am using login button like this:
<?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>

for logout use anchor instead of submit button.
try the following code :
Html::a('logout','site/logout',['class'=>'btn btn-primary','data-method'=>'POST']);

Related

Yii Modal Size reset

I have changed the modal size to large in yii to modal popup window using ajax crud extension by following code.
<?php Modal::begin([
"id"=>"ajaxCrudModal",
"footer"=>"",// always need it for jquery plugin
'options' => [
'class' => 'slide',
'tabindex' => false, // important for Select2 to work properly
],
'size'=>Modal::SIZE_LARGE
])?>
When i click delete button it shows modal in small size and after that size of create modal window previously made large is reset to small. How can i set delete modal to large also. So that is should not reset to small.

Yii2 submit form and return the result in Pjax container

How to submit the form, process the data, send it to action and in the end, place it in the pjax container? I know solution where the pjax container is wrapping the form but my case is something like this:
$form = ActiveForm::begin();
...
...
...
ActiveForm::end();
some html
Pjax::begin(['id' => 'container']);
The result from the controller action goes here
Pjax::end():
I've seen solution like this with javascript/jQuery function along ago but can't find it now. Can some give me example or at least some useful link. Thank you in advance! P.s. Red a lot of articles but couldn't fine something for my case.

Kartik Gridview conflict with my templates menu

I have a template that i was using for my project.
Look at the picture below:
This is when i am not using the kartikGrid. the dropdown menu running as well as the template want.
look at the image below:
this is when i use kartik, the dropdown menu not running anymore.
can some body tell me why it happen.
The template using different bootsrap version with kartik.
thaks.
Hope some body help me.
Imaginaroom, that did the trick for me thank you.
My top menu wasn't responding (direct link, or drop down menu) after kartik was used. I added an id to my menu widget and it did the trick.
echo Nav::widget([
'id' => 'topMenuID',
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
Manually assign different ids to all widgets, so there won't be any conflicts.
If you don't assign ids to widgets, yii gives them one automatically, but the problem occures when loading data with ajax or pjax, then Yii cannot know which ids are already used in the page.
Every widget in Yii2 has a property 'id' that you can assign in configuration array when calling a widget.
Add this code in layout or page that has problem:
$this->registerJs( "$(document).ready(function() { $('.dropdown-toggle').dropdown(); });", View::POS_END, 'ecommerceProductJs' );

CakePHP htmlhelper::image adds atribute class depending on the referenced image folder

I try to display an image with the following code.
<?php echo $this->Html->image('/img/adverts/001/ad.jpg', array('alt' => 'ad')); ?>
this creates me this:
<img class="zdrwtxgldzisqmpzuclb" src="/img/adverts/001/ad.jpg" alt="werbung">
I don't know where this strange class atribute is comming from but it seams to ruin my code as the picture is not displayed.
Now if I use another sub folder in webroot/img, the sub folder uploads like this:
<?php echo $this->Html->image('/img/uploads/001/ad.jpg', array('alt' => 'ad')); ?>
it works and gives back an <img> tag without that class.
<img src="/img/uploads/001/ad.jpg" alt="werbung">
So the question is, where does this class attribute come from, and is this the reason why no image is displayed? I can't find anything about that effect and where it is coming from.
If I add a class attribute to my CakePHP code then it just appends this strange string after my class attribute.
<?php echo $this->Html->image('adverts/01/ad.jpg', array('alt' => 'werbung', 'class' => 'img' )); ?>
<img src="/img/adverts/01/ad.jpg" alt="werbung" class="img zdrwtxgldzisqmpzuclb">
Of course the both folders uploads and adverts have the same rights.
Edit: ndm was right, it is an ad-blocker. Shocking, I didn't know they are that clever.
ndm was right. It was the ad blocker "Adblocker Plus" that caused that effect.
The problem is solved.

Submit 'links' with CakePHP formHelper

Is it possible to create a submit 'link' with CakePHP 2.4's FormHelper? I'm trying to put some less-used submit buttons from my POST form into a Bootstrap dropdown and am running into trouble since they only seem to be able to create a button, which won't work in a dropdown.
Since this is inside a form already, clearly this isn't what I want a postLink for- but is there any good Cake way around this? postLink just makes a plain link, but it won't play well inside another form.
echo $this->Form->button('Download Excel CSV', array(
'type' => 'submit',
'class' => '',
'formaction' => '/posts/csv',
));
Just use the HtmlHelper's url() method:
<button type="button" formaction="<?php echo $this->Html->url('/posts/csv'); ?>">
Click Here
</button>
(I realize you don't want it in a button element, but - showing the concept).
Side note: you should really be using an array instead of a hard-coded formaction:
$this->Html->url(array('controller'=>'posts', 'action'=>'csv'));