【问题标题】:Cakephp 2.5. : how to use html tags and autoLinkUrls in this case蛋糕PHP 2.5。 : 在这种情况下如何使用 html 标签和 autoLinkUrls
【发布时间】:2016-10-18 11:13:26
【问题描述】:

我有一个这样的文本部分:

<p><?php echo __('<strong>some strong text</strong> some other text  THIS IS AN URL more other text <strong>more strong text</strong> and finally end of text'); ?></p>

我想知道最好的方法是:

  • 在这样的文本行中使用 html 标签(因为我需要使用 i18n 翻译)
  • 如何在文本中间添加 url?

在设置 URL 时,我也想使用 $this-&gt;Html-&gt;Link() 的蛋糕样式,但我不知道如何在上面的示例中做到这一点?

【问题讨论】:

    标签: html cakephp text helper


    【解决方案1】:

    Read the manual.

    在翻译消息中使用变量 翻译函数允许您使用在消息本身或已翻译字符串中定义的特殊标记将变量插入到消息中:

    echo __("Hello, my name is {0}, I'm {1} years old", ['Sara', 12]);
    

    只需生成链接 $link = $this-&gt;Html-&gt;link(__('foo'), [/*...*/]); 并将 $link 传递给 __() 函数的第二个参数,如上例所示。

    阅读有关翻译功能的整个部分,还有一些更好的知识,例如复数/单数和数字处理。

    【讨论】:

    • 嗨,谢谢你的例子。是否可以通过这种方式添加链接? __('这是我的 ', ['link text', '..'])
    【解决方案2】:

    这里是怎么做的。

    <p>
        <?php 
             $string = '<strong>some strong text</strong> some other text ';
             $string .= 'https://www.example.com';
             $string .= ' more other text <strong>more strong text</strong> and finally <b>end of text</b>';
             echo $this->Html->link(__($string),'http://www2.test.com',['escape'=>false]); 
         ?>
    </p>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-31
      • 1970-01-01
      • 2022-01-23
      • 2015-11-30
      • 2017-05-16
      • 2012-10-06
      • 2011-05-18
      • 2019-11-29
      相关资源
      最近更新 更多