Cakephp how to remove underline on links - php

New to cakephp came across a scenario where I have to make a text and an image a link.
Fortunately it was successful, however I noticed that there is an underline on my link and I have to remove it, as you can see on the picture below + the code on how I made it like that:
Cakephp Code:
echo $this->Html->link(
$this->Html->image('img/f.png', array('height' => '40', 'width' => '40'))
. '' . ('forensics express&nbsp&nbsp&nbsp&nbsp'),
'http://example.com', array('escape' => false));
normally this would be easy just by adding:
style="text-decoration:none"
in the css, however since I'm new to cake I am not aware of the syntax on how I can put an id or class that I can use for css, or in what I prefer, directly adding the style="text-decoration:none" in the array.I tried this one but it didn't work.
echo $this->Html->link(
$this->Html->image('img/f.png', array('height' => '40', 'width' => '40'))
. '' . ('forensics express&nbsp&nbsp&nbsp&nbsp'),
'http://example.com', array('escape' => false,'style'=>'text-decoration:none'));
How can I solve this? Any help is appreciated

This may help
echo $this->Html->link(
$this->Html->image('img/f.png', array('height' => '40', 'width' => '40'))
. '' . ('forensics express&nbsp&nbsp&nbsp&nbsp'),
'http://example.com', array('escape' => false,'class'=>'no-decoration'));
In the stylesheet, you can create this class
.no-decoration{
text-decoratino:none;
}
You can use this as reference link : How to call CSS class on a CakePHP Html->link?

Just set it in your css (stylesheet) like this, instead of inline code.
a {text-decoration:none;}

Related

Print an image using a predefined image preset pragmatically

I simply need to print out an image via php in Drupal 7. I already have 3 presets, thumnail, medium and large. Does anyone know the exact code I need to print these out as I cannot seem to work it out?
As far as I know, in Drupal 6 it was something like this:
<img src="<?php print 'sites/default/files/imagecache/**thumbnail**/' . $node->field_image_cache['0']['filepath']; ?>" />
I'd be very grateful for any help.
Use theme_image_formatter.
E.g.
print theme("image_formatter", array(
'image_style' => 'thumbnail',
'item' => array(
'uri' => 'sites/default/files/image.jpg',
'alt' => t(""),
'title' => t(""),
'attributes' => array(),
),
));

CakePHP – html helper how to turn off escaping?

I use Cake 2.2.2, and to build a link I use HtmlHelper.
<?php echo $this->Html->link('Link',array('controller' => 'mycontroller', 'action' => 'myAction', '3'."#map"), array('escape' => false));?>
I need to pass value 3 to my controller and I also need the link to have #map (html anchor).
But despite the fact that I use array('escape' => false), output appears to be escaped and #map becomes 3%23map.
Where I made a mistake? Thanks.
http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::url
you need to use
<?php echo $this->Html->link('Link', array(..., '#' => 'map'), ...);?>

How to add <b> tag in HTML helper

I am try add <b> tag inside <a> in cake php
I need output like that
<b>Logout</b>
but i dont how to add tag in this code
<?php echo $this->Html->link('Logout', '/users/logout'); ?>
Please keep in mind that styling should not be part of your HTML Output and - as already suggested by my previous posters - should be in your CSS.
However, there you go (note the escape=false):
echo $this->Html->link(
'<b>' . __('Logout') . '</b>',
array(
'controller' => 'users',
'action' => 'logout',
),
array(
'escape' => false,
)
);
or even more HtmlHelper magick:
echo $this->Html->link(
$this->Html->tag('b', __('Logout')),
array(
'controller' => 'users',
'action' => 'logout',
),
array(
'escape' => false,
)
);
Edit: added Ish Kumar's suggestion for localisation, in cakephp 2.0 we don't need the "true" anymore ;)
One more thing: if you use escape=false keep in mind to sanitize the tags content (in this case the <b>Logout</b>) by yourself, especially if its generated user content e.g. <b>$userInputVar</b>.
My advice would be don't try to use the helpers for every single task, additionally you should use CSS to add bold to the logout link.
echo $this->Html->link('Logout', array('controller'=>'users', 'action'=>'logout'), array('class' => 'logout'));
Then in your CSS:
.logout {
font-weight: bold;
}
Update: If you REALLY REALLY must use deprecated HTML tags in your code:
echo $this->Html->link('<b>Logout</b>', array('controller'=>'users', 'action'=>'logout'), array('class' => 'logout', 'escape' => false));
That's the equivalent of doing this:
<b><?php echo $this->Html->link('Logout', '/users/logout'); ?></b>
As Dunhamzzz noted, you're better off using a CSS class and styling it that way.

How to markup CakePHP Form to allow Text inputs inside a radio group

I am using CakePHP and the FormHelper to generate my form.
However, I need to create a markup similar to the following structure:
(radio1) [TEXT_INPUT] or more credits
(radio2) No Limit
Now, I am not sure how to approach this, but logically I would imagine it to be something like:
$options = array(
'oneormore' => $this->Form->input( 'text_for_oneormore' ) . ' or more credits',
'nolimit' => 'No Limit'
);
echo $this->Html->radio( 'quantity', $options, array() );
Does anyone have any ideas they can offer? I am stumped on this issue.
One way would be to use the 'before' and 'after' options which append the string you put in there. I think you can get away with entire fields there.
http://book.cakephp.org/view/1393/options-before-options-between-options-separator-a
Another way would be to make your own helper based on the FormHelper.
I may be a bit late to the show, but I came across this issue in upgrading a site to cakephp 2.x. I found if I use the "'hiddenField' => false" option, I was able the separate the radio buttons and put text or select inputs between them:
Your question relates to which of the following:<br>
<?php
echo $this->Form->radio("qOption", array('0' => 'Find a store'), array("label" => false, 'hiddenField' => false));
echo $this->Form->radio("qOption", array('2' => 'Choose a Product'), array("label" => false, 'hiddenField' => false));
echo $this->Form->select('product', $products, array());
echo $this->Form->radio("qOption", array('1' => 'Other'), array("label" => false, 'hiddenField' => false));
echo $this->Form->input("other", array("class"=>"f_12_darkgray", "size"=>"40", 'div' => false, "label" => false));
?>

CakePHP - how to use Helpers to make an image link with target="_blank"

This seems like it should be simple, but I'm new to CakePHP. Maybe it's just something I should write in good ole HTML, but - was hoping to find out how do to this with CakePHP's HTML helper.
I just want an image link that has target="_blank".
This is what I tried:
<?php echo $this->Html->link($this->Html->image('tmp/728x90.jpg',
array('alt'=>'advertisement', 'height'=>'90',
'width'=>'728')),'http://www.google.com', array('target'=>'_blank')); ?>
(all in one line - just broke up for ease of viewing)
But when I do this, I get this:
<img src="/img/tmp/728x90.jpg" alt="advertisement" height="90" width="728" />
Any help is greatly appreciated.
Answer (thanks deceze)
<?php
$image = $this->Html->image(
'tmp/300x600.jpg',
array(
'alt'=>'advertisement',
'height'=>'600',
'width'=>'300'
)
);
echo $this->Html->link(
$image,
'http://www.google.com',
array(
'target'=>'_blank',
'escape' => false
)
); ?>
<?php echo $this->Html->link($this->Html->image('fb2.jpg',array('alt'=>'facebook', 'height'=>'90','width'=>'728')),'http://www.facebook.com', array('target'=>'_blank','escape'=>false)); ?>
You need to tell HtmlHelper::link not to HTML escape the input.
This is all very well documented in the manual.
The exact code will be like this
<?php
echo $this->Html->link(
$this->Html->image('tmp/728x90.jpg',
array(
'alt'=>'advertisement', 'height'=>'90',
'width'=>'728')
),
'http://www.google.com',
array(
'target'=>'_blank',
'escape'=>false)
);
?>
You need to use the Html->image . Check it out:
http://book.cakephp.org/view/1441/image
Like mentioned in the Cook Book, you can use the 'url' option of the image method:
echo $this->Html->image("recipes/6.jpg", array(
'alt' => "Brownies",
'url' => array('controller' => 'recipes', 'action' => 'view', 6)
));
echo $html->link("more",array('controller' => 'users', 'action' => 'index/welcome'), array('style'=>'_blank'), false, false);?> image('more-arrow.png', array('alt' => 'more','height'=>'11','width'=>'17'))?>

Categories