CakePHP how to use the PaginatorHelper output follows the effect? - cakephp

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

Related

Cakephp span in Html link

I have this code
<li id="Tiempo">
<?= $this->Html->link(__('En Tiempo'), ['action' => 'index', 'Tiempo']) ?><span class="label label-success ml-10"><?php echo $entiempo ?></span>
</li>
But i want the span into a but I don't know how
You have to modify the content/title of the link. As the docs point out, this is the first parameter of HtmlHelper->link(). To add the span inside your a tag you have 2 options.
Add the Span in the Link
You could either modify it directly and set the escape options to false:
<li id="Tiempo">
<?= $this->Html->link('<span class="label label-success ml-10">' . $entiempo . '</span>', ['action' => 'index', 'Tiempo'], ['escape' => false]) ?>
</li>
Modify the template
Or you modify the template HtmlHelper uses.
$this->Html->setTemplates([
'link' => '{{content}}</span>',
]);
and use the link() method like this:
<?= $this->Html->link($entiempo, ['action' => 'index', 'Tiempo']) ?>
See Changing the Tags Output by HtmlHelper

Form element inside html element not working in cakephp

I have read the documentation and tried all the possible solution but no gain.
This is my html code
<?php echo $this->Html->link(
$this->Form->button("Continue", ["type" => "button", "class"=>"btn btn-dark btn-theme-colored btn-flat mr-5"]),
array(
'controller' => 'my_controller',
'action' => 'my_action'
));?>
I want to have a button inside <a> tag but it is outputting the button in '' " tags.
This is what i want
<i>
<button></button>
</i>
All special chars will be converted to html entities, unless you disable this behavior, using escape option. Code below should output what you want:
<?php echo $this->Html->link(
$this->Form->button("Continue", ["type" => "button", "class"=>"btn btn-dark
btn-theme-colored btn-flat mr-5"]),
array(
'controller' => 'my_controller',
'action' => 'my_action'
),
array(
'escape' => false
));?>
More about HTML helper can be found here: https://book.cakephp.org/3.0/en/views/helpers/html.html#creating-links

cakephp, how to link with two span

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

Cakephp Paginator Custom Styling

I am using the Paginator Component and Helper.
My Code block for Styling is as follows.
<!-- Pagination -->
<div class="pagination">
<ul class="pages">
<li class="prev"><</li>
<li>1</li>
<li>2</li>
<li>3</li>
<li class="next">></li>
</ul>
</div>
When i try to create the pagination using the following
<!-- Pagination -->
<div class="pagination">
<ul class="pages">
<?php if($this->Paginator->hasPrev()) echo $this->Paginator->prev('<', array('tag' => 'li', 'escape' => false)); ?>
<?php echo $this->Paginator->numbers(array('separator' => false, 'tag' => 'li', 'currentClass' => 'active')); ?>
<?php if($this->Paginator->hasNext()) echo $this->Paginator->next('>', array('tag' => 'li', 'escape' => false)); ?>
</ul>
</div>
The Active class is given to the li tag but my template uses the active class to the a-href tag
is there any way i can make cake give it to the a tag?
You will have to extend and override the PaginatorHelper::number() method for that.
Then use your customized paginator helper app wide by using the aliasing feature to make it available as $this->Paginator in your views to replace it in all views.
public $helpers = array(
'Paginator' => array(
'className' => 'MyPaginator',
)
);
Instead of overwriting the whole method you could do this as well:
public function numbers($options = array()) {
$numbers = parent::numbers($options);
/* see explanation below */
return $numbers;
}
Explanation: Use DOM or regex to find, modify and replace the <li class="active"><a></a></li> active <li> element with your modification. This might be the better way because if the core behavior changes you just need to adept your replacement logic instead of having to figure out what has changed in the code and update your method. This bootstrap paginator helper does it this way.

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

Resources