I was trying to pass the last inserted id through form action in Cakephp when i click on a button.
I am a newbie in Cakephp. Here is the code i found out. Can you suggest the correct method tho get the last inserted is through Form?
<?php echo $this->Html->link('View Quote', array('controller' => 'Stockcheck', 'action' => '../Quote/QuoteNo=Q1-1'), array('class' => 'button')); ?>
QuoteNo=Q1-1 should be my last inserted id and QuoteNo is my field
Try this code :
echo $this->Html->link('View Quote', array('controller' => 'Stockcheck', 'action' => '../Quote/', $your_id));
for more help please read this link
<?= $this->Form->postLink('<i class="fa fa-trash-o"></i><span class="hidden-xs"> ' . __('Delete') . '</span>', ['_name' => 'delete-administrator', $administrator->id], ['confirm' => "Are you sure you want to delete {$administrator->full_name}?", 'class' => 'btn btn-sm red', 'escape' => false, 'title' => 'Delete administrator details']); ?>
<?= $this->Form->postLink('<i class="fa fa-trash-o"></i><span class="hidden-xs"> ' . __('Delete') . '</span>', ['_name' => 'edit-administrator', $administrator->id], ['class' => 'btn btn-sm red', 'escape' => false, 'title' => 'Edit administrator details']); ?>
- Using route name
Related
First i want to say that i know there is many post about jQuery and Yii2 around the network but still can't make it clear for me! My question is pretty simple for you i think. When a user is with User role permission he shouldn't be able to update or delete others posts. And so if the user is this kind of guy i want to make both anchors ('Edit' and 'Delete') with opacity 0.5.
This is my view part:
<?php $form = \yii\bootstrap\ActiveForm::begin([
'method' => 'post'
]);
?>
<div class="col-md-8 text-left">
<?= Html::a('Edit', ['update', 'id' => $model->post_id], ['class' => 'btn btn-primary']); ?>
<?=
Html::a('Delete', ['delete', 'id' => $model->post_id],
['data-method' => 'POST', 'class' => 'btn btn-danger']);
?>
</div>
<div class="col-md-4 text-right">
<?= Html::a('Back', 'index', ['class' => 'btn btn-warning']); ?>
</div>
<?php \yii\bootstrap\ActiveForm::end(); ?>
I have added my file to AppAsset.php(test.js):
public $js = [
'js/slide-show.js',
'js/test.js'
];
I know how to make my fucntion but do not know how to implement it. Think i should do it with if statement (if(user->isGuest){ execute function and make anchros with opacity 0.5 }). Can you guys teach me the right way? Will be thankful for every advice! Thank you in advance!
You could assign a disable option so the button is displayed but disabled
if (Yii::$app->user->isGuest) {
echo Html::a('Edit', ['update', 'id' => $model->post_id], ['class' => 'btn btn-primary',
'disabled' => 'disabled']);
echo Html::a('Delete', ['delete', 'id' => $model->post_id],
['data-method' => 'POST', 'class' => 'btn btn-danger',
'disabled' => 'disabled']);
}
I tried to add extra action buttons. Admin only view this button after button click update in a single field in the database.
<p>
<?php
if(!Yii::$app->user->isGuest ){
echo Html::a('Recommended', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
echo Html::a('Not Recommended', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to reject this application?',
'method' => 'post',
],
]);
} else if(Yii::$app->user->can('admin')){
}
?>
</p>
My problem is that I have 3 users that are: applicant, faculty and admin (or hod). In this case after faculty recommendation, the admin (or hod) sanctioned the leave.
I create leave application and faculty recommended, so now I want get the recommended data when admin login to the site.
If admin is the username you should follow this way :
<p>
<?php
if(!Yii::$app->user->isGuest ){
echo Html::a('Recommended', ['update', 'id' => $model->id],
['class' => 'btn btn-primary']);
echo Html::a('Not Recommended', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to reject this application?',
'method' => 'post',
],
]);
} else if(Yii::$app->user->identity->username == 'admin' ){
echo Html::a('Your Button Label for Admin',
['yourActionForAdmin', 'id' => $model->id],
['class' => 'btn btn-primary']);
}
?>
</p>
I have a link that has a button class.
I need to place an icon in the button, so the span tag is needed to do that, but I can't give span the class. I tried like this
<span class="glyphicon glyphicon-search"></span>
This is my link
<?php echo $this->Html->link(
$this->Html->tag('span',__('Crear Pacientes',true)),
array('controller' => 'pacientes', 'action' => 'add'),
array('escape' => false, 'class' => 'btn btn-info')
);
?>
How can I add the class to the span tag?
You can use 'escape'=>false option
<?php
echo $this->Html->link(
'<span class="glyphicon glyphicon-search"></span>',
array(
'controller'=>'pacientes',
'action'=>'add'
),
array(
'escape'=>false,
'class'=>'btn btn-info'
'escape'=>false //NOTICE THIS LINE ***************
)
);
?>
see Explanation Here
or, add array('class' => 'glyphicon glyphicon-search')
<?php
echo $this->Html->link(
$this->Html->tag(
'span',
__('Crear Pacientes',true),
array('class' => 'glyphicon glyphicon-search') //NOTICE THIS LINE ***************
),
array(
'controller'=>'pacientes',
'action'=>'add'
),
array(
'escape'=>false,
'class'=>'btn btn-info'
)
);
?>
I'd like to add a icon <i> tag to a Cakephp link.
Here is my code :
<?= $this->Html->link($this->Html->tag('i', '', array('class' => 'fa fa-shopping-cart')).'Cart', array('controller' => 'shop', 'action' => 'cart')) ?>
This line generates :
<i class="fa fa-shopping-cart"></i>Cart
Why < is replaced by its hexa value? My charset is UTF-8.
Thanks!
Add option 'escape' set to false:
<?= $this->Html->link($this->Html->tag('i', '', array('class' => 'fa fa-shopping-cart')).'Cart', array('controller' => 'shop', 'action' => 'cart'), array('escape' => false)) ?>
Documentation page about HtmlHelper.
Html->link($this->Html->tag('i', '',['class' => 'fa fa-shopping-cart']).'Cart',['controller' => 'shop', 'action' => 'cart'], ['escape' => false]); ?>
[below translated from translate.google.com]
I'm looking for the syntax of how to make a button disabled in CakePHP and I can not get a result; My application need to first save a field for a button to finish the whole process after another button. The first button is a submit and redirects to the same page. The second button performs a function of the controller and go to the next process. I want to prevent the user to go to the next procedure without saving the first; I already have a variable that defines whether it is safe or not, just do not know how to make the Finish button is disabled;
Button code:
echo $this->Html->link(
$this->Html->tag('span', '', array('class' => 'glyphicon glyphicon-ok')) . " Finalizar",
array('controller' => 'Questoes','action' => 'limparSession'),
array('role' => 'button', 'class' => 'btn btn-success', 'escape' => false)
);
Add the disabled class to your button:
<?php
echo $this->Html->link(
$this->Html->tag('span', '', array('class' => 'glyphicon glyphicon-ok')) . " Finalizar",
array(
'controller' => 'Questoes',
'action' => 'limparSession'
),
array(
'role' => 'button',
'class' => 'btn btn-success disabled',
'escape' => false
)
);
?>
This is a bootstrap feature related to the given class.
If you want to do it without bootstrap:
<?php
echo $this->Html->link(
$this->Html->tag('span', '', array('class' => 'glyphicon glyphicon-ok')) . " Finalizar",
array(
'controller' => 'Questoes',
'action' => 'limparSession'
),
array(
'role' => 'button',
'class' => 'btn btn-success',
'disabled' => 'disabled',
'escape' => false
)
);
?>
echo $this->Form->button(
$this->Html->tag('span', '', array('class' => 'glyphicon glyphicon-ok'))." Finalizar",
array('type' => 'submit','onclick' => 'this.disabled=true;return true;',
'class' => 'btn disabled', 'escape' => false)
);