I have the following Link Format which i want to display using Cakephp HTML helper
<a href="product_n1_details.html" title="" class="view_image">
<img src="images/slider/1n.jpg" alt="">
<div class="link_overlay icon-search"></div>
</a>
What i have tried?
<?php echo $this->Html->link($this->Html->image('products/'.$pro['Product']['display_photo']."<div class=\'link_overlay icon-search\'></div>", array('alt' => $pro['Product']['name'])), array('controller' => 'products', 'action' => 'view', $pro['Product']['id']), array('escape' => false, 'class' => 'view_image') ); ?>
The image helper returns the entire <img> tag, so put the div code after your image helper call (spaced out for clarity):
echo $this->Html->link(
$this->Html->image(
'products/'.$pro['Product']['display_photo'],
array(
'alt' => $pro['Product']['name']
)
) . "<div class='link_overlay icon-search'></div>", // put it here!
array(
'controller' => 'products',
'action' => 'view',
$pro['Product']['id']
),
array(
'escape' => false,
'class' => 'view_image'
)
);
scrowler is correct.
All Html helper functions return strings so if you want to make it a little cleaner for yourself you could do this
$image = $this->Html->image( . . . );
$div = $this->Html->tag( 'div', ... );
Then finally
echo $this->Html->link( $image . $div, ... );
Hope that helps.
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,
),
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>
The code below in not working
<?php echo $this->Html->link($this->Html->image('ilmelogo.png'),array('controller'=>'pages','action'=>'feedback')); ?>
But this code is working. Help me out
<?php echo $this->Html->image('ilmelogo.png'); ?>
Can you try this,
echo $this->Html->link(
$this->Html->image('ilmelogo.png'),
'/pages/feedback',
array('class' => 'button', 'target' => '_blank')
);
OR
<?php
echo $this->Html->link(
$this->Html->image("ilmelogo.png", array("alt" => "ilme Logo")),
array(
'controller' => 'pages',
'action' => 'feedback'
)
);
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'));
}
}