简体   繁体   中英

Convert current <a> into CodeIgniter “anchor”

I have the current code

<a href="http://localhost/dashboard.php">
  <i class="fa fa-dashboard"></i>
  <span class="menu-text"> Dashboard </span>
</a>

I'm trying to convert it to the standard that code Igniter uses with the anchor tag. I'm assuming it would be similar to

<?= anchor('dashboard/index', 'Dashboard') ?>

But I'm not sure how to get the other tags and classes in there. Thoughts?

Third parameter ,

<?= anchor('dashboard/index', 'Dashboard','class="fa fa-dashbaord"') ?>

for the span you can just add it directly on the second param

<?= anchor('dashboard/index', 
           '<i class="fa fa-dashboard"></i>
            <span class="menu-text"> Dashboard </span>',
           'class="fa fa-dashbaord"') ?>

note: be carefull with the single qoutes and double qoutes.

DOCUMENTATION

anchor(uri segments, text, attributes)

In your case:

anchor('dashboard/index', 'Dashboard',array('class' => 'fa fa-dashboard','id'=>'your_id','title'=>'Link_title'))
//You can add multiple attributes in an array.nice class by the way

see documentation

Try like this :

echo anchor('dashboard/index', 'My News', 'title="News title"');

Orignal syntax is :

anchor(uri segments, text, attributes);

Details are here .

You can also try it like this

$dashboard  =   '<i class="fa fa-dashboard"></i><span class="menu-text"> Dashboard </span>';
<?= anchor('dashboard/index', '$dashboard') ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM