Welcome Guest, Not a member yet? Register   Sign In
How to avoid using <?=base_url();?> in link href?
#1

[eluser]shinokada[/eluser]
I am using <?=base_url();?> everywhere.

For example,

Code:
[removed][removed]

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

or

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

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

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

How can I set it up?
#2

[eluser]huzzi[/eluser]
If you CI codes in the root folder then you don't have to use base_url() .. someone correct me if i'm wrong.
#3

[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.
#4

[eluser]mcr_rm[/eluser]
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.

http://ellislab.com/codeigniter/user-gui...elper.html
http://ellislab.com/codeigniter/user-gui...elper.html


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.
#5

[eluser]sharpe[/eluser]
use html base tag
Code:
<base href = "<?php echo base_url()?>" />
in the head section.




Theme © iAndrew 2016 - Forum software by © MyBB