开发者

CodeIgniter: Anchor or a href?

Whats difference in using anchor in CodeIgniter instead of using traditional html a href tag? Should I use anc开发者_如何学JAVAhor in Views or HTML a href? Thanks


I honestly feel like there is minimal difference. I personally use html anchor because it uses more html.

If you want to add context path inside a view, just do this:

<a href="<?=site_url('path/name');?>">anchor</a>

However, one of the advantages of using codeigniter anchor is that, if you want to build contents dynamically:

for($i = 0; $i < $count; $i++) {
   $anchors[] = anchor('path/name', 'anchor');
}

is easier than

for($i = 0; $i < $count; $i++) {
   $anchors[] = '<a href="'.site_url('path/name').'">anchor</a>';
}

Do you see the difference? :)


anchor in CodeIgniter can do things like prefix the context path, so you just need to provide the URL of your controller (e.g. '/login') rather than the whole path to your application.

When you use A HREF, you have to ensure your paths are always relative or include the entire path to your app (i.e. /someapp/login).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜