Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter助手重复HTML代码片段_Php_Codeigniter_Codeigniter 3 - Fatal编程技术网

Php Codeigniter助手重复HTML代码片段

Php Codeigniter助手重复HTML代码片段,php,codeigniter,codeigniter-3,Php,Codeigniter,Codeigniter 3,我用的是CI3 我有一段代码(包含在下面)在我的网站上显示社交共享链接。该代码仅在某些视图上是必需的。HTML代码是 <!-- Sharingbutton Facebook --> <a class="resp-sharing-button__link" href="https://facebook.com/sharer/sharer.php?u=http://www.example.com<?php echo .$result['id'] ?>" target="

我用的是CI3

我有一段代码(包含在下面)在我的网站上显示社交共享链接。该代码仅在某些视图上是必需的。HTML代码是

<!-- Sharingbutton Facebook -->
<a class="resp-sharing-button__link" href="https://facebook.com/sharer/sharer.php?u=http://www.example.com<?php echo .$result['id'] ?>" target="_blank" aria-label="Share on Facebook">
  <div class="resp-sharing-button resp-sharing-button--facebook resp-sharing-button--large"><div aria-hidden="true" class="resp-sharing-button__icon resp-sharing-button__icon--solid">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18.77 7.46H14.5v-1.9c0-.9.6-1.1 1-1.1h3V.5h-4.33C10.24.5 9.5 3.44 9.5 5.32v2.15h-3v4h3v12h5v-12h3.85l.42-4z"/></svg>
    </div>Share on Facebook</div>
</a>

<!-- Sharingbutton Twitter -->
<a class="resp-sharing-button__link" href="https://twitter.com/intent/tweet/?text=Super%20fast%20and%20easy%20Social%20Media%20Sharing%20Buttons.%20No%20JavaScript.%20No%20tracking.&amp;url=http%3A%2F%2Fsharingbuttons.io" target="_blank" aria-label="Share on Twitter">
  <div class="resp-sharing-button resp-sharing-button--twitter resp-sharing-button--large"><div aria-hidden="true" class="resp-sharing-button__icon resp-sharing-button__icon--solid">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M23.44 4.83c-.8.37-1.5.38-2.22.02.93-.56.98-.96 1.32-2.02-.88.52-1.86.9-2.9 1.1-.82-.88-2-1.43-3.3-1.43-2.5 0-4.55 2.04-4.55 4.54 0 .36.03.7.1 1.04-3.77-.2-7.12-2-9.36-4.75-.4.67-.6 1.45-.6 2.3 0 1.56.8 2.95 2 3.77-.74-.03-1.44-.23-2.05-.57v.06c0 2.2 1.56 4.03 3.64 4.44-.67.2-1.37.2-2.06.08.58 1.8 2.26 3.12 4.25 3.16C5.78 18.1 3.37 18.74 1 18.46c2 1.3 4.4 2.04 6.97 2.04 8.35 0 12.92-6.92 12.92-12.93 0-.2 0-.4-.02-.6.9-.63 1.96-1.22 2.56-2.14z"/></svg>
    </div>Share on Twitter</div>
</a>

我不想在每个视图上复制/粘贴这个代码段,我想我可以创建一个助手函数,并将其包含在我想要显示代码段的页面上——这可能吗

所以我的观点看起来像

// some html here
<?php social_share_links_helper() ?>
// more html here
//这里有一些html
//更多的html在这里
我在
helpers/social\u share\u links\u helper.php
中创建了一个空文件,并且在我的控制器中包含了
$this->load->helper(“social\u share\u links”)

我不知道下一步该怎么做才能在
social\u share\u links\u helper()中
echo
html

也许有更有效的方法


任何建议都将不胜感激。

是的,您可以在您创建的帮助者的帮助下进一步操作。您可以这样做:

只需在
social\u share\u links\u helper.php中创建一个函数名
social\u share\u links


你是否考虑过,在你的视图文件夹中创建一个自己的代码>社会共享?PHP<代码>视图,只需通过<代码> > $> ->加载>视图(“社会共享”);代码>在这些视图中,你需要它在哪里?好的,我用你的变量名更新了我的答案,在链接中添加其他链接,就像它一样如果我的答案帮助你,请也接受它作为答案
function social_share_links()
{
    /*Just replace your anchor here with yours */
    $social_links = '<a class="resp-sharing-button__link" href="https://facebook.com/sharer/sharer.php?u=http://www.example.com/'.$result['id'].' target="_blank" aria-label="Share on Facebook">
                    <div class="resp-sharing-button resp-sharing-button--facebook resp-sharing-button--large">
                        <div aria-hidden="true" class="resp-sharing-button__icon resp-sharing-button__icon--solid">
                              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
                                  <path d="M18.77 7.46H14.5v-1.9c0-.9.6-1.1 1-1.1h3V.5h-4.33C10.24.5 9.5 3.44 9.5 5.32v2.15h-3v4h3v12h5v-12h3.85l.42-4z"/>
                              </svg>
                        </div>Share on Facebook
                    </div>
                  </a>';

   /*Other link here*/
   $social_links .= '<a href=""></a>';

   echo $social_links;
}
<div class="row">
   <?php social_share_links();?>
</div>