按钮内的symfony图片? [英] symfony image inside a button?

查看:88
本文介绍了按钮内的symfony图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用symfony1.4将此代码包含在按钮内的图像:

I'm trying to include an image inside a button using symfony1.4 with this code:

<?php 
    echo button_to(image_tag('icon.png')."button_name",'url-goes-here');
?>

但是我得到的结果而不是我想要的是一个带有"img src = path/to/the/icon.png button_name"作为按钮值的按钮.我已经用了足够长的时间在Google上搜索,却一无所获,所以我尝试在这里询问.

But the result i get, instead of what i want is a button with "img src=path/to/the/icon.png button_name" as the value of the button. I've google'd it long enought and found nothing, so i'll try asking here.

我想找到一种生成类似于html的html的方法:<button><img src=..>Text</button>,但是在onclick选项中关联了symfony url

i'd like to find the way to generate html similar to:<button><img src=..>Text</button> but with a symfony url associated in the onclick option

我该怎么做才能将图像放在带有symfony的按钮中?我使用助手的方式有误吗? 谢谢您的时间!

How can i do it to put an image inside a button with symfony? Am i using the helpers wrong? Thank you for your time!

推荐答案

我终于创建了自己的助手来显示这种按钮.我知道这不是非常有效和灵活,但适用于我自己的情况.这是代码

I finally created my own helper to display this kind of buttons. I know is not very efficient and flexible but works in my case. Here is the code

function image_button_to($img,$name,$uri,$options){
  $sfURL = url_for($uri);
  $sfIMG = image_tag($img);
  if(isset($options['confirm'])){
    $confirm_text = $options['confirm'];
    $jsFunction = 'if(confirm(\''.$confirm_text.'\')){ return window.location=\''.$sfURL.'\';}else{return false;}';
  }else{
    $jsFunction = 'window.location="'.$sfURL.'";';
  }
  $onclick = 'onclick="'.$jsFunction.'"';
  if(isset($options['title'])){
    $title = 'title=\''.$options['title'].'\' ';
  }else{
    $title = '';
  }
  if(isset($options['style'])){
    $style = 'style=\''.$options['style'].'\' ';
  }else{
    $style = '';
  }
return '<button type="button" '.$onclick.$title.$style.' >'.$sfIMG." ".$name.'</button>';
}

使用此功能作为帮助者,在模板中,我只需要:

With this function as helper, in the templates i just have to:

<?php echo image_button_to('image.png',"button_name",'module/actionUri');?>

希望这对某人有用;)

这篇关于按钮内的symfony图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆