2014-11-05 74 views
0

首先,我在這裏搜索了這個問題,並找到了一些答案,但他們不適合我。我的代碼有點不同。在CodeIgniter的Anchor中添加類

這是我的錨結構;

<?php echo anchor($this->lang->switch_uri('tr')); ?> 

我需要在此菜單結構中使用此錨;

<li><a class="nav-icon"><i><img src="<?php echo site_url('assets/panel/flags/tr.png'); ?>" width="16" /></i> Türkçe</a></li> 

在此先感謝。

回答

0

看看URL助手;

https://ellislab.com/codeigniter/user-guide/helpers/url_helper.html

echo anchor('news/local/123', 'My News', array('title' => 'The best news!')); 

將產生:<a href="http://example.com/index.php/news/local/123" title="The best news!">My News</a>

所以,你會;

echo '<li>' . anchor('#', '<img src="img_path" /> Text', array('class' => 'myClass')) . '</li>'; 
+0

謝謝,但我已經知道,我的問題是這部分; '$ this-> lang-> switch_uri('tr')' – birlikbilisim 2014-11-05 16:00:37

+0

對不起 - 我不認爲我曾經使用過switch_uri函數。無法在user_guide中找到它。 – Craig 2014-11-05 16:06:20

0

我找到了答案。它應該是這樣的;

<li><a href="<?php echo site_url($this->lang->switch_uri('tr')); ?>" class="nav-icon"><i><img src="<?php echo site_url('assets/panel/flags/tr.png'); ?>" width="16" /></i> Türkçe</a></li> 
0

您可以通過在錨點中創建一個數組來添加一個類。

例如

<?= anchor('your link here', 'Name of the anchor', array('title' => 'your anchor title', 'class'=>'your anchor class here')) ?> 

,你想有一個錨將這個。

+0

它工作得很好。謝謝 – 2017-06-17 04:18:43

相關問題