![CodeIgniter](https://2.bp.blogspot.com/-r7g_YeB-NTQ/V0lW1e95hSI/AAAAAAAAC1o/bhW4YMd7ydQykOypeSd4xlfr15lhAvshACK4B/s1600/codeigniter%2B-%2Bpetanikode.png)
Fungis
base_url()
and site_url()
are two functions for retrieving web URLs in the CodeIgniter framework. Both of these functions can be used by activating the helper url
first.
Function base_url()
the function
base_url()
will generate a basic url based on the configuration filled in config.php
. Suppose the configuration is like this.$config['base_url'] = 'http://petanikode.com/';
So, when we use a function
base_url()
, we get a value:http://petanikode.com/
Function site_url()
As the name implies, the function
site_url()
will generate a URL or web address along with the index file. Suppose the web configuration is as follows.$config['base_url'] = 'http://petanikode.com/';
$config['index_page'] = 'index.php';
So, when we use a function
site_url()
, we get a value:http://petanikode.com/index.php
When base_url()
and when to site_url()
use?
After the results obtained from the function, we can guess for ourselves when the right time to use it.
The function is
base_url()
usually used to create a URL from a resource that is in the (root) web directory . For example, make URL assets like the following.![Example URL Base Function](https://1.bp.blogspot.com/-EUamVuxQjSg/V0lS0Bkh_BI/AAAAAAAAC1E/KYwq8_MGsM4kNi-bIqY-jvWCVYLf1DtpACK4B/s1600/Contoh%2Bpenggunaan%2Bfungsi%2Bbase_url%2Bcodeigniter%2B-%2Bpetanikode.png)
Meanwhile, functions are
site_url()
often used to make URLs to Controllers or in other words, this function is used to access certain Controllers.
Examples of its use are as follows:
![Example of Using site_url ()](https://2.bp.blogspot.com/-HXg3x6Hj7uo/V62O31kbnyI/AAAAAAAADIs/HVEUePK8JTQK48MpMkpMFY2jXMG8p7jWgCK4B/s1600/Penggunaan%2Bfungsi%2Bsite_url%2Buntuk%2Bmengakses%2Bcontroller%2BCI%2B-%2BPetani%2BKode.png)
Another example use of the function
site_url()
to shift (redirect) .![Use Site URL to redirect](https://2.bp.blogspot.com/-aOcIvxTEusw/V62PbakJ2mI/AAAAAAAADI0/cLRBz_hE-YsXYVroi9shLYlmtxx4hmPFwCK4B/s1600/Penggunaan%2Bfungsi%2Bsite_url%2Buntuk%2Bredirect.png)
Conclusion
The function
base_url()
and function site_url()
are the help functions of the helper url .
This function is used to retrieve the basic URL and web URL.
The function is
base_url()
used to build a url to access the current resource in the web root directory .
While the function is
site_url()
used to access certain controllers .
More or less, that's my conclusion. Maybe something is not right, please add it.
0 Komentar untuk "What is the difference in the function base_url () with the function site_url () in CodeIgniter?"
Silahkan berkomentar sesuai artikel