What is the base_url() function in CodeIgniter?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex CodeIgniter topics. It also reveals how well you can explain technical ideas to non-experts.
Answer
The base_url() function returns the base URL of your application as configured in app/Config/App.php ($baseURL). Example: if your app is at https://example.com, then base_url("assets/css/style.css") returns https://example.com/assets/css/style.css. Use it in views for links and asset URLs: <link href="<?= base_url("css/style.css") ?>">. Related helper: site_url() prepends the index file if used. current_url() returns the full URL of the current page. previous_url() returns the referring URL. Always use these helpers rather than hardcoding URLs, so the app works regardless of where it is deployed (subdirectory, different domain, etc.).
Common Mistake
A common mistake is memorizing definitions without understanding implications. When asked this question, go one level deeper — explain what happens when this concept is misused or ignored.