cakephp, how to link with two span - cakephp

How to add two span tags to a link?
<?php echo $this->Html->tag('span’,
$this->Html->link($v['name']['lastname'],
$v['link’]
);
?>
//Output
<a class=« test" href="./#">
<span>name</span>
<span>lastname</span>
</a>
I'm not sure to be a good start, thank you for the help

Simply concatenate two span tags with the HtmlHelper in the first argument of the link() method.
echo $this->Html->link(
$this->Html->tag('span', $v['name']) .
$this->Html->tag('span', $v['lastname']),
$v['link'],
array('escape' => false)
);

I believe this should do it:
<?php echo $this->Html->link('<span>name</span><span>lastname</span>', '#', array('escape' => false)); ?>

Related

In my <a> tag, there are lots of code HTML. How to add Html link (CakePHP)

My code:
<a href="#">
<div class="list_content">
<p class="title"><?php echo $note['Note']['title']; ?></p>
<p class="create_at"><?php echo $note['Note']['create_at'] ?></p>
<p> <?php echo substr($note['Note']['content'], 0,100) . '...' ?></p>
</div>
</a>
How to add <?php echo $this->Html->link('...') ?> in CAKEPHP 2.x
If you want to insert HTML element in any HTML helper, you have to add 'escape' => false. Check the document https://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::link
Simple Example:
$this->Html->link('<b>My Content</b>','#',[
'escape' => false
]);
For you case:
$this->Html->link(
$this->Html->div('list_content',
$this->Html->para('title',$note['Note']['title']).
$this->Html->para('create_at',$note['Note']['create_at']).
$this->Html->para(null,substr($note['Note']['content'], 0,100) . '...')
),
'#',
['escape' => false]
);
If you are going to use Aman's answer, remember that by setting 'escape' => false you are disabling a default security feature. So you probably want to make sure you then escape any user input using the h() method:-
$this->Html->link(
$this->Html->div('list_content',
$this->Html->para('title', h($note['Note']['title'])).
$this->Html->para('create_at', h($note['Note']['create_at'])).
$this->Html->para(null, substr(h($note['Note']['content']), 0,100) . '...')
),
'#',
['escape' => false]
);
If you've got a lot of markup you want inside your <a> tags it is sometimes simpler to use $this->Html->url() instead (and can lead to more readable code):-
<a href="<?= $this->Html->url('#') ?>">
<div class="list_content">
<p class="title"><?php echo $note['Note']['title']; ?></p>
<p class="create_at"><?php echo $note['Note']['create_at'] ?></p>
<p> <?php echo substr($note['Note']['content'], 0,100) . '...' ?></p>
</div>
</a>
The only real disadvantage I am aware of doing this second example is that you lose any functionality that you may add to $this->Html->link(), but I suspect this isn't a concern for the majority of users.

cakephp get the url of image from post

I would get the image url: mysite/img/test.png but I get this link: mysite/posts/test.png
<?php echo $this->Html->link(
$this->Html->image($post['Post']['image']),
$post['Post']['title']),
array('escape' => false)
);
?>
I have to get another way the url?
Edit:
If you want link to your image, you can do in this way.
<?php echo $this->Html->link(
$this->Html->image($post['Post']['image']),
$this->Html->url('/img/'.$post['Post']['image']),
array('escape' => false)
);
?>
or
<a href="<?php echo $this->Html->url('/img/'.$post['Post']['image']); ?>">
<?php echo $this->Html->image($post['Post']['image']); ?>
</a>

CakePHP how to use the PaginatorHelper output follows the effect?

I hope the output effect:
<li class="prev"><i class="icon-previous"></i></li>
The Official Handbook:
You can change the wrapping tag using the tag option:
echo $this->Paginator->prev(__('previous'), array('tag' => 'li'));
Output:
<li class="prev">
<a rel="prev" href="/posts/index/page:1/sort:title/order:desc">
previous
</a>
</li>
I imitate the way it:
<?php
echo $this->Paginator->prev(__('<i class="icon-previous"></i>'), array('tag' => 'li'));
?>
But the output is:
<li class="prev"><i class="icon-previous"></i></li>
What should I do?
try:
echo $this->Paginator->prev(
__('previous'),
array('tag' => 'li', 'class' => 'icon-previous')
);
echo $this->Paginator->prev(__('<i class="icon-previous"></i>'),
array(
'tag' => 'li',
'escape'=>false
));
Also make sure there IS a previous record otherwise the tag is omitted anyway

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)
)
);

Html markup in cakephp's $html->link, eg. $html->link('<span>Hey</span>')?

I have this block of code in a cakephp .ctp file:
<h1>
<?php echo $this->Html->link('Hello <span>Stack Overflow</span>',
array('controller'=>'pages', 'action'=>'home')); ?>
</h1>
But instead of the html being formatted, I'm seeing it literally:
<h1><a href="/rrweb/www/hub/pages/home">
Hello <span>Stack Overflow</span></a></h1>
Any idea's?
Thanks!
You need to disable HTML entity conversion:
echo $this->Html->link(
'Hello <span>Stack Overflow</span>',
array('controller'=>'pages', 'action'=>'home'),
array('escape' => FALSE)
);
or
echo $this->Html->link('Hello', array('controller'=>'pages', 'action'=>'home')).' '.$this->Html->tag('span', $this->Html->link('Stack Overflow', array('controller'=>'pages', 'action'=>'home')), array());

Resources