• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to avoid using <?=base_url();?> in link href?

I am using <?=base_url();?> everywhere.

For example,


<link rel="stylesheet" href="<?= base_url();?>css/jqaccordion.css" />


<form method="post" action="<?=base_url();?>index.php/jquery/ajaxprocess/" id="ajaxform">

I have seen using without <?=base_url();?>.http://www.weblee.co.uk/2009/06/07/simpl...er-part-1/

<form method="post" action="/jquery/processform/" id="myform">

How can I set it up?

If you CI codes in the root folder then you don't have to use base_url() .. someone correct me if i'm wrong.

[eluser]Rick Jolly[/eluser]
[quote author="huzzi" date="1262904051"]If you CI codes in the root folder then you don't have to use base_url() .. someone correct me if i'm wrong.[/quote]
Yes, if you use absolute urls (starting with a "/"). But that isn't portable since you can't be sure you'll never move to a subdirectory. You can use <base href="<?=base_url()?>"/> in the head and then make all your urls relative.

Depends how you have your application set up. Personally I use Base url methods in my header include files as I pass all views through a template which includes the header and footer or individual calls to load the header and footer view files in other views. I then have at max around five base_url calls to include sme scripts.

The rest of the things you reference could be cleared up by using CI form helper to open your forms (automatically includes the correct path) and url anchor method for links etc.


If you are not using standard header includes etc for views then that is perhaps something to look at.

The method above with the single slash is the absolute path as mentioned by Rick and this is not helpful should you reuse your appication in a sub directory or need to scale in any way.

use html base tag
<base href = "<?php echo base_url()?>" />
in the head section.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.