What's better? Using 'base_url ()' or './'?

I have been using CodeIgniter Framework for several months now.

In views, I usually include external css and js with base_url()

like this:

<link href="<?php echo base_url() ?>assets/css/custom.css" rel="stylesheet">

      

But someone tells me that using it ./

also works. And it is true.

So which is better (safe)?

+3


source to share


4 answers


base_url () is the best choice to use. The cost difference is not related to the relative or full URL, and you know it will point you to the right place.



It's a best habit and you can pass URL parameters to it and save the code neatly.

+3


source


base_url()

is just a helper (URL helper in CI). Some people are just easier to use, so I don't see any additional security with base_url()

.

In the case of ease of use, I see that so many people use it as

<?php echo base_url()."controller/function";?>

      



while actually you can use it like

<?php echo base_url("controller/function");?>

      

+2


source


You can use either, but its good practice in Codeigniter to use base_url ().

+2


source


you can use ./

instead base_url()

. ./ is the root directory of your codeIgniter installation and in most cases this tub will be like base_url()

that, but base_url()

best used because it ./

doesn't work on some server or some other problem.

+1


source







All Articles