Cakephp html link with image + text, without using css - cakephp

How can I create html link that has text and image both using cakephp Html helper as below
<a href="#">
<img src="images/icons/web-app/48/add-user.png" width="48" height="48"> Add User
</a>
I want final result as
I know that I can do that with css, but I just want to know how is it possible using cakephp

echo $this->Html->link($this->Html->image('design/unige_logo.png', array('width' => '48', 'height' => '48')) . ' ' . __('Add user'),
'#',
array('escape' => false));

Related

How to add <i> and <span> tag inside a tag in cakephp 3?

My html code is given below:
<a href="/patients/index" class="m-menu__link ">
<i class="m-menu__link-bullet m-menu__link-bullet--dot">
<span></span>
</i>
<span class="m-menu__link-text">
Add Medicines
</span>
</a>
and i want to convert it by using HtmlHelper in cakephp 3.
You want to use the 'escape' => false parameter in the link() method. This stops Cake from escaping the markup:-
<?= $this->Html->link(
'<i class="m-menu__link-bullet m-menu__link-bullet--dot"><span></span></i><span class="m-menu__link-text">' . h('Add Medicines') . '</span>',
'/patients/index',
[
'escape' => false,
'class' => 'm-menu__link'
]
) ?>
It's important to remember to still escape any user generated content using h(). I've shown this in the example above by escaping 'Add Medicines', but if this is hardcoded you wouldn't need to wrap it in the h() method.
The below code for add and tag inside a hyperlink in cakephp 3
<?php echo $this->Html->link(
$this->Html->tag("i", "<span></span>",array("class" => "m-menu__link-bullet m-menu__link-bullet--dot")).$this->Html->tag("span", "Add Medicine",
array("class" => "m-menu__link-text")),
["controller"=>"Medicines", "action"=>"index"],
["class"=>"m-menu__link",
"escape"=>false]
);
?>

CakePHP - Trying to use an image instead of a text to link to somewhere else

I´m quite new to CakePHP ... I am using CakePHP 3 and want display an image in a <td>, that links to an URL or a Javascript function.
$this->Html->tag('td', $this->Html->link($this->Html->image('/img/do_something.png'), array('action' => 'do_something')))
My problem is, that the image isn´t displayed but instead it shows:
<img src="/img/do_something.png" alt=""/>
Any ideas ?
Reading the manual usually helps:
HTML special characters in $title will be converted to HTML entities.
To disable this conversion, set the escape option to false in the
$options array.
echo $this->Html->link(
$this->Html->image("recipes/6.jpg", ["alt" => "Brownies"]),
"recipes/view/6",
['escape' => false]
);
Will output:
<a href="/recipes/view/6">
<img src="/img/recipes/6.jpg" alt="Brownies" />
</a>
burzum's answer about using 'escape' => false on the link works great and gives you the ability to easily set attributes on both the link and image. However, if you just simply want to link an image you can do this by setting the url option on the image:-
$this->Html->image(
'/do_something.png',
[
'url' => ['action' => 'do_something']
]
);
Which will give you something like:-
<a href="/controller/do_something">
<img src="/img/do_something.png" alt="" />
</a>
As burzum mentioned, it's all clearly explained in the docs.
Simply Do :
$this->Html->image('image.jpg',['url' => ['action' => 'action_name']]
);

Outputting multiple elements within <a> using CakePHP HTML Helper

I'd like to know if this code...
echo $this->Html->link(
"<h3>test</h3>".$this->Html->image("image.jpg")."<p>Some text</p>",
"/link",
array('escape' => false)
);
...is the best way to generate this HTML in CakePHP...
<a href="/path/to/link">
<h3>test</h3>
<img alt="" src="/path/to/image.jpg">
<p>Some text</p>
</a>
Or, is there a more "correct" way of doing this? I want the and all to be within the tag so that I can set the to display: block; in CSS and have the whole area clickable with a hover effect.
Something tells me that having HTML echoed like this isn't the right way to go about it, but I can't see an alternative if I'm going to use the HTML Helper. Is there one?
Just use the URL method of the HTML helper instead of the link one,do the rest as static HTML, may as well keep the amount of PHP down to a minimum as far as I see it.
<a href="<?php echo $this->Html->url($params); ?>">
<h3>test</h3>
<?php echo $this->Html->image($params); ?>
<p>Some text</p>
</a>
This would be the most efficient way of doing this task. But maybe you should think about your markup structure and what you want to achieve...
I use
$this->Html->tag('li',
$this->Html->link(
'<i class="entypo-book"></i>'.
$this->Html->tag('span', $nom
.$this->Html->tag('span', '32', array('class' => 'badge'))
),
array('controller' => 'Pages', 'action' => 'index'),
array('class' => 'active', 'title' => 'Pages', 'escape' => false)
)
);

CakePHP HTML link

I am trying to use CakePHP HTML Linker for the following code
<li class="iAdd"><span>Add Cuisine</span></li>
Since the span tag needs to be inside the a tag. am not able to get the output as need. Any suggestions on how to get it done ?
Disable the escape option in your link code, like so:
<li class="iAdd">
<?php echo $this->Html->link(
'<span>Add Cuisine</span>',
array('action' => 'add'),
array('escape' => false) // This line will parse rather then output HTML
); ?>
</li>
you can always use normal html in links:
$this->Html->link('<span>'.h($text).'</span>', array('action'=>'add'), array('escape'=>false));

how to write this code with cakephp 1.3 html helper?

i try to use gallery prettyphoto but i have problem with this code..how to write this code with cakephp html helper
<li><a href="images/fullscreen/2.jpg" rel="prettyPhoto[gallery1]">
<img src="images/thumbnails/t_2.jpg" width="60" height="60" alt="Nice building" /></a></li>
The key part is to turn off HTML escaping for the link text (as it contains an HTML image tag). Also, images are usually stored in the paths like /img/... but that will depend on your implementation.
<li><?php
$thumb = $this->Html->image('images/thumbnails/t_2.jpg', array(
'width' => 60,
'height' => 60,
'alt' => 'Nice building',
));
echo $this->Html->link($thumb, 'images/fullscreen/2.jpg', array(
'rel' => 'prettyPhoto[gallery1]',
'escape' => false, // important
));
?></li>

Resources