How to design the link in cakephp3 while using reverse routing - cakephp-3.0

How to design the link in cakephp3 while using reverse routing? I have an anchor tag and that has a class but in reverse routing it already has the anchor and it is in array, so how can I design the link like background and add class?
Note: I want to design the anchor tag which name is cancel in my program
<div class="btn btn-secondary waves-effect w-md">
<?=
$this->Html->link(
'Cancel', array('controller' => 'Users', 'action' => 'dashboard')
);
?>
</div>
I have tried to add another array but it didn't work.

Html->link('Edit', array('controller' => 'Users', 'action' => 'edituser'),
array('class' =>"btn btn-custom waves-light waves-effect w-md")
);?>

Related

Form is not showing the btn bootstrap class in Laravel Blade

I imported "laravelcollective/html":"^5.4.0" and my form is working fine but I have this issue with the btn bootstrap class, it is not showing at all, but labels, text and textarea are.
{!!
...
{{ Form::submit('Create Post', null, array('class' => 'btn btn-success btn-lg btn-block')) }}
...
!!}
I am using Laravel 5.4.
What am I doing wrong? Thanks.
Never mind. I had null as an argument. Working now!

Update 2 containers using Pjax

I'm working on a transport planner in Yii2.
The tasks are shown in a GridView.
Above the GridView I have a navigation to go through the dates.
like so:
<?php Pjax::begin(['enablePushState' => false]); ?>
<ul id="planner_nav">
<li>
<?= Html::a('', ['planner/previous'], ['class' => 'btn btn-default glyphicon glyphicon-arrow-left pull-left']) ?>
</li>
<li>
<?= Html::a(Yii::t('app', $session->get('date')), ['#'], ['class' => 'planner_date']); ?>
</li>
<li>
<?= Html::a('', ['planner/next'], ['class' => 'btn btn-default glyphicon glyphicon-arrow-right pull-right']) ?>
</li>
</ul>
<?php Pjax::end(); ?>
As you can see the current date is stored in a session.
The date is set using DateTime().
In my actionIndex in the Planner-model I pass the datesession to the PlannerSearch-model like:
$dataProvider = $dataModel->data(Yii::$app->request->queryParams, $session->get('datum'));
And then grab the session: PlannerSearch::search($params, $date), and use the $date variable in my query.
Maybe a terrible way of doing things, but I'm still a Yii (mvc) beginner..
What I actually want to achieve, is to go through the dates and update both the planner navigation date (.planner_date) and the GridView in the planner-view with the tasks for that day.
Anyone who can help?

Confirm message not working on postLink with icon

I need some help with a postLink created with FormHelper in CakePHP 3. The normal postLink works just fine like this:
<?= $this->Form->postLink(__('Delete'),
['action' => 'delete', $member->id],
['confirm' => __('Are you sure, you want to delete {0}?', $member->name)]) ?>
But when I try to use a font-awesome icon / i-tag instead of the text link, the confirmation message is not showing up anymore. The icon itself is showing correctly and the action still works fine, just the message is not working.
I used the following posts for help, but the examples in the answers there are not working for me:
CakePHP equivalent of html code
CakePHP delete confirmation
I tried these two approaches:
<?= $this->Form->postLink('<i class="fa fa-trash"></i> ',
['action' => 'delete', $member->id],
['escape' => false],
['confirm' => __('Are you sure, you want to delete {0}?', $member->name)]) ?>
<?= $this->Form->postLink(
$this->Html->tag('i', '', ['class' => 'fa fa-trash']),
['action' => 'edit', $member->id],
['escape' => false],
['confirm' => __('Are you sure you want to delete {0}?', $member->name)]); ?>
I'm still very new to CakePHP and tried to look this up in the book, but that did not help me. I also tried the exact syntax as shown in the SO links above, which seemingly worked for some others...but the confirmation message is still not working for me.
What am I doing wrong here?
escape and confirm options should be in the same array. Function postLink() looks like this:
postLink(string $title, mixed $url = null, array $options =[])
So working code for you will be:
<?= $this->Form->postLink('<i class="fa fa-trash"></i> ',
['action' => 'delete', $member->id],
[
'escape' => false,
'confirm' => __('Are you sure, you want to delete {0}?', $member->name)
]
) ?>

Blade, Use html inside variable being passed into partial view is not being rendered

I'm using a partial view to display page header, that view accepts two variables one is Icon the other is a title.
pageHeader.blade.php:
<div class="page-header">
<div class="row">
<!-- Page header, center on small screens -->
<h1 class="col-xs-12 col-sm-4 text-center text-left-sm"><i class="fa {{$icon}} page-header-icon"></i> {{$title}}</h1>
</div>
and I'm using it like so:
#include('zdashboard._partials.pageHeader',['icon'=>'fa-pencil','title'=>'<strong>Editing</strong>'.$center->translations()->whereLang('en')->first()->name])
Sometimes I like to make one word strong or italic like the example above but, blade engine won't render the HTML tags I'm typing as part of title variable (the output like the photo down).
So is there any idea how to solve this? Am I doing it!
wrong?
The output
By default in Laravel 5 {{ $title }} construction wil be escaped.
If you don't want the data to be escaped, you may use the following syntax:
{!! $title !!}
Read more about Blade control structures: http://laravel.com/docs/5.0/templates#other-blade-control-structures
view
#if(Session::has('success'))
<div class="alert alert-success">
{!! Session::get('success')!!}
</div>
#endif
Controller
public function store(Request $request)
{
$this->validate($request, [
'product_code' => 'required|unique:products',
'product_name' => 'required',
'description' => 'required',
'price' => 'required',
'brand_id' => 'required',
'category_id' => 'required',
]);
$product = Product::create([
'product_code' => $request->input('product_code'),
'product_name' => $request->input('product_name'),
'description' => $request->input('description'),
'price' => $request->input('price'),
'brand_id' => $request->input('brand_id'),
'category_id' => $request->input('category_id'),
]);
return redirect()->route('products.index')->with('success',
"The product <strong>".$product->product_name."</strong> has successfully been created.");
}

How to add content inside link in cakephp

I would like to have content inside my link with cakephp. I know I can use this syntax to have an image inside my link
$this->Html->image("recipes/6.jpg", [
"alt" => "Brownies",
'url' => ['controller' => 'Recipes', 'action' => 'view', 6]
]);
For an HTML output like this :
<a href="/recipes/view/6">
<img src="/img/recipes/6.jpg" alt="Brownies" />
</a>
But the above code idn't quite what I'm looking for. I would like to have the following HTML output
<a href="/recipes/view/6">
<div>
<img src="/img/recipes/6.jpg" alt="Brownies" />
</div>
</a>
I came with this code witch could work but I will have to figure out the full path link.
<a href="<?= '/recipes/view/6' ?>">
<div>
<?= $this->Html->image("recipes/6.jpg", ["alt" => "Brownies"]); ?>
</div>
</a>
Is there a more robust way of doing what I want with cakephp?
I am not sure if this is a more robust way, but you could possibly do something like this:
<?php
echo $this->Html->link(
$this->Html->div(null, $this->Html->image('/img/recipe/6.jpg')),
array('controller' => 'recipes','action' => 'view', 6),
array('escape' => false)
);
?>
And the output would be this:
<a href="/recipes/view/6">
<div>
<img alt="" src="/img/recipes/6.jpg">
</div>
</a>
You can use Link or URL mechanism.
Using Link
echo $this->Html->link(
$this->Html->div(null,
$this->Html->image('recipes/6.jpg', ['alt' => 'Brownies'])),
array('controller' => 'Recipes', 'action' => 'view', 6),
array('escape' => false)
);
Using URL
Adding the URL inside the HTML
<a href="<?= $this->Html->url( array('controller' => 'Recipes', 'action' => 'view', 6),
array('escape' => false)); ?>" class="light_blue">
<div>
<?= $this->Html->image("recipes/6.jpg", ["alt" => "Brownies"]); ?>
</div>
</a>