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]); ?>
Related
I've managed to generate menu using Zend Navigation. However, the active page is never set (active class is not set for any <li> element).
My partial:
foreach ($pages as $page): ?>
<?php if (!$page->isVisible() || !$this->navigation()->menu()->accept($page)) continue; ?>
<li role="presentation" <?php if ($page->isActive()) echo 'class="active"' ?>>
<a href="<?php echo $page->getHref() ?>">
<?php if ($icon = $page->get('icon')) {
echo '<span class="' . $icon . '"></span>';
} ?>
<span> <?php echo $this->translate($page->getLabel()) ?> </span>
</a>
</li>
<?php endforeach ?>
Extract of module.config.php:
'navigation' => array(
'default' => array(
array(
'label' => 'Page 1',
'route' => 'application/default',
'namespace' => 'Application\Controller',
'controller' => 'Index',
'action' => 'page1',
'icon' => 'fa fa-2x fa-file-text',
'order' => 10,
),
array(
'label' => 'Page 2',
'route' => 'application/default',
'namespace' => 'Application\Controller',
'controller' => 'Index',
'action' => 'page2',
'icon' => 'fa fa-2x fa-file-text',
'order' => 20,
),
),
),
The menu is rendered properly on the page, but without any active class:
$partial = array('partial/menu.phtml', 'default');
echo $this->navigation('navigation')
->menu()
->setMinDepth(0)
->setMaxDepth(0)
->setPartial($partial);
After some research into ZF code, I've found something I don't understand (in Zend\View\Helper\Navigation\Menu.php):
// in renderNormalMenu function, line 288
$isActive = $page->isActive(true);
Any idea or suggestion regarding my problem?
Thanks a lot,
Problem was in module.config.php ; the isActive method (from Zend\Navigation\Mvc) was expected the "full" controller name (including namespace).
My config was splitting namespace and controller name, wich causes the issue.
Solution:
array(
'label' => 'Page 1',
'route' => 'application/default',
'controller' => 'Application\Controller\Index',
'action' => 'page1',
'icon' => 'fa fa-2x fa-file-text',
'order' => 10,
),
[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)
);
I am new in cakephp and i have to create a link with 2 tags like following html
<li><i class="fa fa-th-list"></i> <span>Shop</span></li>
And in cake php i did something like this:
<li><?php echo $this->Html->link(
// $this->Html->tag('i', array('class' => array('fa', 'fa-th-list'))),
$this->Html->tag('span', 'Video / Imagini', null),
array(
'controller' => 'users',
'action' => 'video',
),
array('escape' => FALSE)) ?></li>
How can i add the tag?
I search to internet and on cake book but no details about the second tag.
Thank you for your time.
Your code was almost correct. I made only some little changes:
<li><?php
echo $this->Html->link(
$this->Html->tag('i', '', array('class' => array('fa', 'fa-th-list'))) .
$this->Html->tag('span', 'Video / Imagini'),
array(
'controller' => 'users',
'action' => 'video',
),
array('escape' => false)
);
?></li>
I was wondering how I go about adding a "#" to a cakephp url without it being escaped. Ive tried 'escape' => false but to no success. I am doing this to try and link to a id="comments" section of the page that has contains the comments. Here is my code for the linking:
<?php echo $this->Html->link($post['Post']['total_comments'].' comments', array('controller' => 'posts', 'action' => 'view', $post['Post']['slug'].'#comments'),array('class' => 'comments-icon')); ?>
Any help would be appreciated.
Try this:
echo $this->Html->link($post['Post']['total_comments'].' comments', array(
'controller' => 'posts',
'action' => 'view',
$post['Post']['slug'],
'#' => 'comments' //Or #comments only without key
), array('class' => 'comments-icon'));
I want to output an image with a hyperlink wrapped around it instead of just a text hyperlink using cakePHP's formHelper::postLink function.
Does anyone know how to do this? I tried multiple things but couldn't get it working.
<?php echo $this->Form->postLink(
'Delete',
array('action' => 'delete', $country['Country']['id']),
array('confirm' => __('Are you sure you want to delete ').$country['Country']['name'].'?')
)?>
So instead of 'Delete' I want to display an image.
Here's what works for me.
echo $this->Form->postLink(
$this->Html->image('icn_trash.png', array('alt' => __('Effacer'))), //le image
array('action' => 'delete', $artist['Artist']['id']), //le url
array('escape' => false), //le escape
__('Êtes-vous sûr de vouloir effacer artiste #%s?', $artist['Artist']['id']) //le confirm
); //le voila
Try this :
echo $this->Form->postLink(
$this->Html->image('delete.png',
array("alt" => __('Delete'), "title" => __('Delete'))),
array('action' => 'delete', $items['Item']['id']),
array('escape' => false, 'confirm' => __('Are you sure?'))
);
If I understand your question correctly I dont think you want to use $this->Form->postLink
I think this page is exactly what you're after: http://book.cakephp.org/view/1441/image
This uses $this->Html->image to create the image and then you can pass a URL through as one of the parameters to specify the surrounding anchor link.
You can wrap in image inside a link element, but you need to set the escape option to false, like this:
echo $this->Html->link(
$this->Html->image('your_image_here.jpg', array(
'alt' => 'Alternative Text for your image',
'title' => 'Optional tooltip text for your image'
),
array(
'controller' => 'YourController',
'action' => 'someAction'
),
array(
'escape' => false // Add this to avoid Cake from printing the img HTML code instead of the actual image
)
);
That should do the trick.
echo $this->Html->link(
$this->Html->image("recipes/6.jpg", array("alt" => "Brownies")),
array(
'controller' => 'recipes',
'action' => 'view',
'id' => 6,
'comments' => false
)
)
function delete_image(){
if ($this->Session->read('Auth.User.id')) {
$this->User->id = $this->Session->read('Auth.User.id');
$this->User->updateAll(
array('User.image' => "''"),
array('User.id' => $this->User->id)
);
$this->Session->setFlash('The image has been deleted.');
$this->redirect(array('action' => 'profile'));
}
}