Codeigniter 4 – URL Helpers with Examples
URL Helpers
- URL Helpers are a set of functions that assist with creating and manipulating URLs.
- URL Helpers are stored in the system/Helpers/URL_helper.php file.
Loading the URL Helper
- Use the helper() function to load the URL Helper.
Example:
helper('url');
Base URL
- Use the base_url() function to get the base URL of the application.
Example:
echo base_url(); // Output: (link unavailable)
Current URL
- Use the current_url() function to get the current URL.
Example:
echo current_url(); // Output: (link unavailable)
Site URL
- Use the site_url() function to get the site URL.
Example:
echo site_url(); // Output: (link unavailable)
Controller URL
- Use the controller_url() function to get the URL of a controller.
Example:
echo controller_url('controller'); // Output: (link unavailable)
Method URL
- Use the method_url() function to get the URL of a method.
Example:
echo method_url('controller/method'); // Output: (link unavailable)
Redirect
- Use the redirect() function to redirect to a URL.
Example:
redirect('controller/method');
Rewrite URL
- Use the rewrite_url() function to rewrite a URL.
Example:
echo rewrite_url('controller/method', 'new_controller/new_method'); // Output: (link unavailable)
I hope this helps! Let me know if you have any further questions or need more information.
Note: The URL Helper is a powerful tool for creating and manipulating URLs in CodeIgniter 4. It can be used in a variety of applications, from creating dynamic URLs to handling redirects.